我们可以使用弹性搜索版本检索以前的 _source 文档吗 [英] Can We Retrieve Previous _source Docs with Elastic Search Versions

查看:16
本文介绍了我们可以使用弹性搜索版本检索以前的 _source 文档吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读 ES 上关于版本控制的博文.

I've read the blog post on ES regarding versioning.

但是,我希望能够从更新中获取以前的_souce"文档.

However, I'd like to be able to get the previous "_souce" documents from an update.

例如,假设我有这个对象:

For example, let's say I have this object:

{
    "name": "John",
    "age": 32,
    "job": "janitorial technician"
}
// this becomes version 1

我将其更新为:

{
    "name": "John",
    "age": 32,
    "job": "president"
}
// this becomes version 2

那么,通过 ES 中的版本控制,我是否能够获得对象以前的作业"属性?我试过这个:

Then, through versioning in ES, would I be able to get the previous "job" property of the object? I've tried this:

curl -XGET "localhost:9200/index/type/id?version=1"

但这只会返回最新的 _source 对象(John 担任总裁的那个对象).

but that just returns the most up-to-date _source object (the one where John is president).

我实际上想像 StackOverflow 那样实现版本差异方面.(顺便说一句,我使用 elastic-search 作为我的主要数据库 - 如果有办法用其他 nosql 数据库做到这一点,我很乐意尝试一下.最好是与 ES 很好地集成的.)

I'd actually like to implement a version differences aspect much like StackOverflow does. (BTW, I'm using elastic-search as my main db - if there's a way to do this with other nosql databases, I'd be happy to try it out. Preferrably, one that integrates well with ES.)

推荐答案

不,您不能使用内置版本控制来执行此操作.所做的只是存储当前版本号,以防止您无序应用更新.

No, you can't do this using the builtin versioning. All that does is to store the current version number to prevent you applying updates out of order.

如果您想保持多个版本可用,那么您必须自己实现.根据您可能想要存储的版本数量,您可以采用三种方法:

If you wanted to keep multiple versions available, then you'd have to implement that yourself. Depending on how many versions you are likely to want to store, you could take three approaches:

对于低音量变化:

1) 将旧版本存储在同一文档中

1) store older versions within the same document

{ text: "foo bar",
  date:  "2011-11-01",
  previous: [
      { date: '2011-10-01', content: { text: 'Foo Bar' }},
      { date: '2011-09-01', content: { text: 'Foo-bar!' }},
  ]
}

对于大量更改:

2) 添加一个 current 标志:

2) add a current flag:

{
   doc_id:  123,
   version: 3,
   text:    "foo bar",
   date:    "2011-11-01",
   current: true
}

{
   doc_id:  123,
   version: 2,
   text:    "Foo Bar",
   date:    "2011-10-01",
   current: false
}

3) 与上面的 (2) 相同,但将旧版本存储在单独的索引中,因此请保留您的实时"索引,该索引将用于您的大多数查询,体积小且性能更高.

3) Same as (2) above, but store the old versions in a separate index, so keeping your "live" index, which will be used for the majority of your queries, small and more performant.

这篇关于我们可以使用弹性搜索版本检索以前的 _source 文档吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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