我们使用一个自定义的_id字段,它是一个long值。我想得到最大的_id值。我要找的是-
{
"stored_fields": [
"_id"
],
"query": {
"match_all": {}
},
"sort": {
"_id": "desc"
},
"size": 1
}但是我从ES 5.1得到了错误,因为-
"reason": {
"type": "illegal_argument_exception",
"reason": "Fielddata access on the _uid field is disallowed"
}那么,如何获得_id的最大值呢?我并不想仅仅为了获得最大值而在文档中存储_id的副本。
发布于 2017-08-01 15:39:41
应该按_uid字段排序,而不是按_id字段排序。无法访问_id字段进行排序(https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-id-field.html)。
{
"stored_fields": [
"_id"
],
"query": {
"match_all": {}
},
"sort": {
"_uid": "desc"
},
"size": 1
}https://stackoverflow.com/questions/45427887
复制相似问题