【问题标题】:Elasticsearch - Get top 'n' values & perform aggregationElasticsearch - 获取前“n”个值并执行聚合
【发布时间】:2018-06-14 14:59:27
【问题描述】:

我有一个索引,我想从中搜索文本并获取前 100 个结果并执行聚合以从这 100 个结果中检索 uniqueIds 并按它们的 max_value/sum_value 对它们进行排序。目前我正在使用下面的查询,它对大约 10 万个结果执行聚合。但我希望此聚合仅限于我的前 100 个结果

{
"size": 0,
"query": {
    "multi_match": {
        "query": "game of thrones",
        "fields": ["Textfield", "Textfield.shingles^3"]
                    }
          },
"aggs" : {
  "Bucketized_Results" : {
        "terms" : {
          "field" : "uniqueId",
            "order": {"max_score": "desc"}
        },
    "aggs": {
        "max_score": {
            "max": {
                "script": "_score"
                   }
        }
    }
    }
}
}

【问题讨论】:

    标签: elasticsearch aggregation elasticsearch-aggregation


    【解决方案1】:

    这行得通:

    {
    "size": 0,
    "query": {
            "multi_match": {
                "query": "game of thrones",
                "fields": ["fullText", "fullText.shingles^3"]
                            }
                  },
      "aggs": {
        "Bucketized_Results": {
          "sampler": {
            "shard_size": 100
          },
          "aggs": {
            "getting_uniqueId": {
              "terms": {
                "field": "uniqueId",
                    "order": {"sum_score": "desc"}
              },
              "aggs": {
                "sum_score": {
                  "sum": {
                    "script": "_score"
                  }
                }
              }
            }
          }
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2016-01-23
      • 2015-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-29
      • 1970-01-01
      • 2020-12-07
      相关资源
      最近更新 更多