gpt4 book ai didi

elasticsearch - 结合基数聚合和 'where'条件?

转载 作者:行者123 更新时间:2023-12-03 00:25:50 27 4
gpt4 key购买 nike

我正在尝试根据字段创建不重复计数匹配,但我遇到了麻烦。

如何将基数和类似"select distinct(lastname) from table where name like 'George%'"的条件结合在一起?

我如何在基数中使用“where”条件?

{
"aggs" : {
"test_count" : {
"cardinality" : {
"field" : "lastname"
}
}
}
}

最佳答案

您是否尝试了以下方法来获取不同的姓氏,使用诸如'George'的firstName

curl -X POST "http://localhost:9200/gccount/Customer/_search?pretty=true" -d'                       
{
"query": {
"fuzzy_like_this_field" : {
"firstName" : {
"like_text" : "George",
"max_query_terms" : 12
}
}
},
"aggs": {
"distinct_lastNames": {
"terms": {
"field": "lastName"
}
}
}
}'

它对我有用,在elasticsearch字段 analyzer中使用默认的 firstName

Es响应
  "aggregations": {
"distinct_lastNames": {
"buckets": [
{
"key": "Upd",
"doc_count": 1
},
{
"key": "Bale",
"doc_count": 2
}
]
}
}

引用,

https://github.com/prayagupd/gccount/blob/master/gccount-analytics/scripts/search_customer_like.sh#L21

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-flt-field-query.html

关于elasticsearch - 结合基数聚合和 'where'条件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25728757/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com