怎么又是你

es term 聚合时能按_score进行排序么

Elasticsearch | 作者 arvin | 发布于2017年05月22日 | 阅读数:9648

es term 聚合时能按_score进行排序么
已邀请:

arvin

赞同来自: laoyang360

目前从文档中发现:
_doc:按照文档数量进行排序。
_term:按照字典进行排序。
自定义:通过子聚合的方式

从工具中查找发现_score是无法进行aggregatable的。

夏李俊

赞同来自: beangou

​{
"size": 0,
"aggregations": {
"DPID": {
"terms": {
"field": "bill.DPID",
"order": {
"top_score": "desc"
}
},
"aggs": {
"top_score": {
"max": {
"script": "_score"
}
}
}
}
}

}

 上面json应该就可以按score排序
光这样可能查询报错:scripts of type [inline], operation [aggs] and lang [groovy] are disabled,那么只需在配置文件elasticsearch.yml里添加一些参数
script.inline: on
script.indexed: on
script.engine.groovy.inline.aggs: on
script.engine.groovy.inline.update: on
 
这4个参数请加在末尾

Cheetah

赞同来自: xinfanwang

一个不和常理的需求,你都聚合了,还管分值干什么,分值是query时候产生的,是一个相关度

夏李俊

赞同来自: beangou

{
  "size": 0,
  "aggregations": {
    "DPID": {
      "terms": {
        "field": "bill.DPID",
        "order": {
          "top_score": "desc"
        }
      },
      "aggs": {
        "top_score": {
          "max": {
            "script": "_score"
          }
        }
      }
    }
  }
}

 上面json应该就可以按score排序
光这样可能查询报错:scripts of type [inline], operation [aggs] and lang [groovy] are disabled,那么只需在配置文件elasticsearch.yml里添加一些参数
script.inline: on
script.indexed: on
script.engine.groovy.inline.aggs: on
script.engine.groovy.inline.update: on
 
这4个参数请加在末尾

hailang

赞同来自:

我也 要通需求 

要回复问题请先登录注册