【问题标题】:How can I aggregate over the _score如何汇总 _score
【发布时间】:2016-08-03 16:11:35
【问题描述】:

我尝试在 Elastic Search 上的 _score 字段上运行聚合查询,但没有结果。似乎无法使用 _score 字段,可能是因为它不是文档的字段。如何汇总 _score ?

这是我的查询:

{
  "_source": false, "explain": false, "from": 0, "size": 0,
  "aggs" : {
    "score_ranges" : {
       "range" : {
          "field" : "_score",
          "ranges" : [
            { "to"   : 50 },
            { "from" : 50, "to" : 75 },
            { "from" : 75 }
          ]
        }
      }
  },
  "query": {
    "function_score": {
      "query": {
        "match_all": { }
      }
    }
  }
}

【问题讨论】:

    标签: elasticsearch aggregate


    【解决方案1】:
      "aggs": {
        "scores_histogram": {
          "histogram": {
            "script": "return _score.doubleValue() * 10",
            "interval": 3
          }
        }
      }
    

    或者,ranges:

      "aggs": {
        "score_ranges": {
          "range": {
            "script": "_score",
            "ranges": [
              {
                "to": 50
              },
              {
                "from": 50,
                "to": 75
              },
              {
                "from": 75
              }
            ]
          }
        }
      }
    

    而且您需要启用动态脚本。

    【讨论】:

      猜你喜欢
      • 2011-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-01
      • 2020-10-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多