问题
We use a custom _id field which is a long value. I would like to get the max _id value. The search I am making is -
{
"stored_fields": [
"_id"
],
"query": {
"match_all": {}
},
"sort": {
"_id": "desc"
},
"size": 1
}
But I get error back from ES 5.1 as-
"reason": {
"type": "illegal_argument_exception",
"reason": "Fielddata access on the _uid field is disallowed"
}
So, how do I go about getting the max value of _id. I don't really want to store copy of _id inside the doc just to get the max value.
回答1:
You should sort by the _uid field not by the _id field. The _id field is not accessible for sorting (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/how-to-get-the-maximum-id-value-in-elasticsearch