如何在ElasticSearch中按_version排序数据 [英] How to sort data by _version in ElasticSearch

查看:343
本文介绍了如何在ElasticSearch中按_version排序数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我能够使用

    {
  "version":true,
  "_source":false,
  "sort": [
    {
      "_score": {
        "order": "desc"
      }
    }
  ], 
  "query": {
    "match_all": {}

  }
}

请让我知道如何使用_version做同样的事情。默认情况下,字段_version不支持Fielddata。所以可能是我缺少了一些东西。
是否有要查询版本的特定设置?
请帮忙!

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!

推荐答案

您无法执行此操作,通常不必这样做。
请参见以下线程:
https://discuss.elastic.co/t/filter-by--version-and-show--version-in-elasticsearch-query/22024/2

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


虽然在某些情况下使用_version似乎可行,但我建议
绝不要将其用于乐观锁定
个更新。特别是,版本没有任何意义:它们看起来像
就像文档被修改的次数一样,但情况并非总是
(例如,如果您创建一个包含与刚删除的文档具有相同的ID
,新文档
的版本号将不是1),更重要的是它是一个实现细节,此
的行为可能会在未来。

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 字段未编制索引,因此您无法在查询中使用它

您可以创建自定义版本字段并手动进行处理。

_version field is not indexed so you can't use it in queries.
You can create you custom version field and handle it manually.

这篇关于如何在ElasticSearch中按_version排序数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆