我正在尝试根据字段创建不同的计数点击次数,但我被卡住了。
如何结合基数和"select distinct(lastname) from table where name like 'George%'"
等条件?
如何使用基数的'where'条件?
{
"aggs" : {
"test_count" : {
"cardinality" : {
"field" : "lastname"
}
}
}
}
答案 0 :(得分:1)
您是否尝试过以下内容来获取不同的lastNames计数,其中firstName
类似于' George'
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"
}
}
}
}'
我在弹性搜索字段analyzer
中使用默认firstName
对我有用。
Es Response
"aggregations": {
"distinct_lastNames": {
"buckets": [
{
"key": "Upd",
"doc_count": 1
},
{
"key": "Bale",
"doc_count": 2
}
]
}
}
参考文献,
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-flt-field-query.html