How to retrieve the maximum id for one type index effectively?
You can also use Max Aggregation (since 1.3) to get the maximum value of a given field in a document.
curl localhost:9200/myindex/mytype/_search -d
'{
"aggs" : {
"max_id" : {
"max" : {
"field" : "id"
}
}
},
"size":0
}'
Will return:
{
"took":7,
"timed_out":false,
"_shards": {
"total":6,
"successful":6,
"failed":0
},
"hits": {
"total":22,
"max_score":0.0,
"hits": []
},
"aggregations": {
"max_id": {
"value": 27.0
}
}
}
In my case the maximum id is 27.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With