Can We Retrieve Previous _source Docs with Elastic Search Versions

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.

Leave a Comment