我们使用一个自定义_id字段,它是一个long值。我想获得最大 _id 值。我正在进行的搜索是 -
{
"stored_fields": [
"_id"
],
"query": {
"match_all": {}
},
"sort": {
"_id": "desc"
},
"size": 1
}
Run Code Online (Sandbox Code Playgroud)
但我从 ES 5.1 收到错误消息:
"reason": {
"type": "illegal_argument_exception",
"reason": "Fielddata access on the _uid field is disallowed"
}
Run Code Online (Sandbox Code Playgroud)
那么,我该如何获取 的最大值呢_id?我真的不想_id在文档中存储副本只是为了获得最大值。
您应该按_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
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2761 次 |
| 最近记录: |