How to sort data by _version in ElasticSearch

情到浓时终转凉″ 提交于 2019-12-13 02:02:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!