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

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

问题描述

我已阅读ES上有关版本控制的博文。



然而,我希望能够从更新中获取以前的_souce文档。



例如,让我们说我有这个对象:

  {
name:John,
age :32,
job:janitorial technician
}
//这成为版本1

我将其更新为:

  {
name:John ,
年龄:32,
工作:总统
}
//这成为版本2
/ pre>

然后,通过ES中的版本控制,我能够获得对象的上一个作业属性吗?我试过这个:

  curl -XGETlocalhost:9200 / index / type / id?version = 1

但是只返回最新的_source对象(John是总裁的对象)。



我实际上希望实现一个版本差异,就像StackOverflow一样。 (BTW,我使用弹性搜索作为我的主要数据库 - 如果有办法与其他nosql数据库这样做,我很乐意尝试,优选,一个与ES完美集成。)

解决方案

不,您不能使用内置版本控制。所有这些都是存储当前的版本号,以防止您更新次序不合适。



如果您想保留多个版本,那么您必须实现那你自己



对于低容量更改



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

  {text:foo bar ,
date:2011-11-01,
上一个:[
{date:'2011-10-01',内容:{text:'Foo Bar'}}
{date:'2011-09-01',content:{text:'Foo-bar!'}},
]
}

对于大量更改



2)添加当前标志:

  {
doc_id:123,
版本:3,
文本:foo bar,
日期:2011-11-01,
当前:true
}

{
doc_id:123,
版本:2,
文本:Foo Bar,
日期:2011-10-01,
current:false
}

3)与上述(2)相同,但将旧版本存储在SE同行索引,所以保持你的活索引,这将被用于大部分的查询,小而且性能更好。


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

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

And I update it to:

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

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"

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

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:

For low volume changes:

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!' }},
  ]
}

For high volume changes:

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) 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天全站免登陆