繁体   English   中英

在Elastic Search中组合聚合

[英]Combining aggregations in Elastic Search

我有一些对象按“ masterID”分组。 我需要一个聚合/查询,以按结果显示“ masterID”使每个对象组的“相关性”最高。

通过聚合术语“ masterID”,我可以获得每个“ masterID”的存储桶。 但是,如何在每个存储桶中获得最高的“相关性”对象?

到目前为止的查询是:

curl -XGET 'http://localhost:9200/pwo/_search?search_type=count&size=0&pretty=true' -d '{
  "aggregations": {
    "masterIDs": {
      "terms": {
        "field": "masterID",
        "size": 0
      }
    }
  }
}
'

curl -XGET 'http://localhost:9200/pwo/_search?size=0&pretty=true' -d '{
  "aggregations": {
    "relevance": {
      "max": {
        "field": "relevance"
      }
    }
  }
}
'

有没有一种方法可以通过单个查询解决此问题?

您可以在masterIDs块中添加相关性聚合块,如下所示:

curl -XGET 'http://localhost:9200/pwo/_search?size=0&pretty=true' -d '{
  "aggregations": {
    "masterIDs": {
      "terms": {
        "field": "masterID",
        "size": 0
      },
      "aggregations": {
        "relevance": {
          "max": { "field" : "relevance" }
        },
        "aggregations": {
          "top_hits": {
            "size": 1
          }
        }
      }
    }
  }
}
'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM