前面的query都会写java的api,但是后面的aggs的嵌套就不知道怎么写了。es版本为5.3.3
GET /realty_assistant/phoneinoutcallrecord/_search
{
"query": {
"bool": {
"must": [
{
"range": {
"dt": {
"gte": 20170401,
"lte": 20170631
}
}
},
{
"term": {
"account.keyword": {
"value": "LNC"
}
}
},
{
"match": {
"callstatus": 0
}
},
{
"match": {
"isphoneno": 1
}
},
{
"match": {
"origin": "phone_in"
}
}
]
}
},
"aggs": {
"accountGroup": {
"terms": {
"field": "account.keyword",
"size": 100000
},
"aggs": {
"distinct": {
"cardinality": {
"field": "phone.keyword"
}
}
}
},
"the_sum": {
"sum_bucket": {
"buckets_path": "accountGroup>distinct.value"
}
}
}
}
GET /realty_assistant/phoneinoutcallrecord/_search
{
"query": {
"bool": {
"must": [
{
"range": {
"dt": {
"gte": 20170401,
"lte": 20170631
}
}
},
{
"term": {
"account.keyword": {
"value": "LNC"
}
}
},
{
"match": {
"callstatus": 0
}
},
{
"match": {
"isphoneno": 1
}
},
{
"match": {
"origin": "phone_in"
}
}
]
}
},
"aggs": {
"accountGroup": {
"terms": {
"field": "account.keyword",
"size": 100000
},
"aggs": {
"distinct": {
"cardinality": {
"field": "phone.keyword"
}
}
}
},
"the_sum": {
"sum_bucket": {
"buckets_path": "accountGroup>distinct.value"
}
}
}
}
2 个回复
laoyang360 - 《一本书讲透Elasticsearch》作者,Elastic认证工程师 [死磕Elasitcsearch]知识星球地址:http://t.cn/RmwM3N9;微信公众号:铭毅天下; 博客:https://elastic.blog.csdn.net
赞同来自:
1) "callstatus": 0 "isphoneno": 1 "origin": "phone_in" 改成term精确匹配;
2)最笨的方法,直接拼接dsl,用Java 检索API对接;
3)稍微复杂的方法,集合termQuery、boolQuery等对接JavaAPI就可以了。
lc1993929
赞同来自: