# Compare documents from two indexes

**URL:** <https://discuss.elastic.co/t/compare-documents-from-two-indexes/233448>\
**Category:** Elasticsearch\
**Created:** [May 20, 2020, 4:12am UTC](https://discuss.elastic.co/t/compare-documents-from-two-indexes/233448 "2020-05-20T04:12:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Veer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/veer/32/68700_2.png) [@Veer](https://discuss.elastic.co/u/Veer)\
**Post date:** [May 20, 2020, 4:12am UTC](https://discuss.elastic.co/t/compare-documents-from-two-indexes/233448/1 "2020-05-20T04:12:08Z")

</div>

Hello. I'm trying to compare two indexes. Index 1 will have the raw data and I'll use Index 2 to store processed data from Index 1. However, I have noticed that when the records in Index 1 are not in sequential order by the time, those set of records doesn't make it to Index 2. So I'm basically trying to do a diff between Index 1 and Index 2.

Sample data in Index 1: (Index 2 will also have same data but with additional fields)

```auto
Index 1:
{
  test_tstamp: 2020-05-19T01:00:00.000Z
  report_tstamp: 2020-05-19T01:00:30.000Z
  created_tstamp: 2020-05-19T01:00:30.000Z
}

```

Let's assume there is a document at every 10 seconds in Index 1(d1, d2, d3, d4, d5) and Index 2 (d1, d4, d5) missed documents between two timestamps. My diff should retrieve the tstamp for missing records (d1, d4).

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [May 20, 2020, 4:14am UTC](https://discuss.elastic.co/t/compare-documents-from-two-indexes/233448/2 "2020-05-20T04:14:31Z")

</div>

Welcome! 😃

This is not something that Elasticsearch can do for you, you'd need to handle this in your client code.

---

<div class="post-metadata">

**Author:** ![Veer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/veer/32/68700_2.png) [@Veer](https://discuss.elastic.co/u/Veer)\
**Post date:** [May 20, 2020, 1:11pm UTC](https://discuss.elastic.co/t/compare-documents-from-two-indexes/233448/3 "2020-05-20T13:11:11Z")

</div>

Thank you @warkolm

---

<div class="post-metadata">

**Author:** ![Hendrik\_Muhs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hendrik_muhs/32/25802_2.png) [@Hendrik\_Muhs](https://discuss.elastic.co/u/Hendrik_Muhs)\
**Post date:** [May 20, 2020, 1:22pm UTC](https://discuss.elastic.co/t/compare-documents-from-two-indexes/233448/4 "2020-05-20T13:22:25Z")

</div>

I think this might be helpful:

[https://www.elastic.co/guide/en/elasticsearch/reference/current/transform-painless-examples.html#painless-compare](https://www.elastic.co/guide/en/elasticsearch/reference/current/transform-painless-examples.html#painless-compare)

If the indexes are large you need something like [transform](https://www.elastic.co/guide/en/elasticsearch/reference/current/transforms.html)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 17, 2020, 1:22pm UTC](https://discuss.elastic.co/t/compare-documents-from-two-indexes/233448/5 "2020-06-17T13:22:26Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
