Elasticsearch - 获得顶级' n'价值观和执行聚合

时间:2018-06-14 14:59:28

标签: elasticsearch aggregation elasticsearch-aggregation

我有一个索引,我想搜索一个文本&获得前100个结果并执行聚合以从这100个结果中检索uniqueIds&按max_value / sum_value对它们进行排序。目前我正在使用下面的查询,该查询对大约100K的结果执行聚合。但我希望这个聚合仅限于我的前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"
                   }
        }
    }
    }
}
}

1 个答案:

答案 0 :(得分:0)

这有效:

{
"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"
              }
            }
          }
        }
      }
    }
  }
}