你不会是程序猿吧?

请教一个多索引字段比对查询写法的问题

Elasticsearch | 作者 tacsklet | 发布于2019年01月16日 | 阅读数:2168

想要实现的功能例子如下:
 
有2个索引: company  person
里面都包含goods和price字段
需要查询出来company和persion中当goods字段的值一样时price字段的值不一样的数据,目前没有头绪,请问该怎样写呢。
已邀请:

rochy - rochy_he

赞同来自: lvwendong tacsklet

对 goods 字段进行 termsAgg,然后设置其子聚合为对 _index 的 termsAgg 子聚合,并设置 min_doc_count 为 2;
最后设置 _index 的子聚合为 topHits,这样就可以找到你需要的数据。
 
{
"size": 0,
"query": {
"match_all": {
"boost": 1.0
}
},
"aggregations": {
"goods": {
"terms": {
"field": "goods",
"size": 10000,
"min_doc_count": 1,
"shard_min_doc_count": 0,
"show_term_doc_count_error": false,
"order": [{
"_count": "desc"
}, {
"_key": "asc"
}],
"collect_mode": "breadth_first"
},
"aggregations": {
"index": {
"terms": {
"field": "_index",
"size": 10,
"min_doc_count": 2,
"shard_min_doc_count": 0,
"show_term_doc_count_error": false,
"order": [{
"_count": "desc"
}, {
"_key": "asc"
}]
},
"aggregations": {
"top": {
"top_hits": {
"from": 0,
"size": 100,
"version": false,
"explain": false
}
}
}
}
}
}
}
}

要回复问题请先登录注册