问题
As I am able to sort data using score like
{
"version":true,
"_source":false,
"sort": [
{
"_score": {
"order": "desc"
}
}
],
"query": {
"match_all": {}
}
}
Please let me know How can I do the same with _version. By default Fielddata is not supported on field _version. So may be I am missing some thing. Is there any specific setting to query with version? Please help!
回答1:
You can't do this, and usually you don't have to. See this thread: https://discuss.elastic.co/t/filter-by--version-and-show--version-in-elasticsearch-query/22024/2
While using the _version might seem to work in certain cases, I would recommend to never use it for anything else than optimistic locking of updates. In particular, versions do not carry any meaning: they might look like the number of times a document has been modified but it is not always the case (for instance if you create a new document which has the same ID as a document that you just deleted, the version number of the new document will not be 1), and more importantly it is an implementation detail, this behaviour might change in the future.
_version
field is not indexed so you can't use it in queries.
You can create you custom version field and handle it manually.
来源:https://stackoverflow.com/questions/47789869/how-to-sort-data-by-version-in-elasticsearch