# Compare fields of different documents in the same index

**URL:** <https://discuss.elastic.co/t/compare-fields-of-different-documents-in-the-same-index/219756>\
**Category:** Kibana\
**Created:** [February 18, 2020, 10:06am UTC](https://discuss.elastic.co/t/compare-fields-of-different-documents-in-the-same-index/219756 "2020-02-18T10:06:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![JamieUnix](https://avatars.discourse-cdn.com/v4/letter/j/71e660/32.png) [@JamieUnix](https://discuss.elastic.co/u/JamieUnix)\
**Post date:** [February 18, 2020, 10:06am UTC](https://discuss.elastic.co/t/compare-fields-of-different-documents-in-the-same-index/219756/1 "2020-02-18T10:06:41Z")

</div>

There are a lot of discussions around this topic but haven't found a solution for my problem.  
I am trying to compare fields of different documents in the same index. For example,let's say i have three documents as below :  
**Index1**  
**Doc** 1  
Field1 = Value1  
Field2 = Value2  
**Doc** 2  
field1 = Value1  
field2 = Value\_2  
**Doc** 3  
field1 = Value\_1  
field2 = Value\_2

I want to display all the documents where Field1.value == field1.value (according to the example, it should display Doc1 and Doc2). I don't know what the value will be, so I can't make a query by value and also I read that scripted fields can't be used here since it works only within a document.  
Documents are bulk imported from two different sources, the comparison can't be done on the client's side.

I really appreciate any help since I am struggling with this for a long time now. Thanks in advance.

---

<div class="post-metadata">

**Author:** ![wylie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wylie/32/81794_2.png) [@wylie](https://discuss.elastic.co/u/wylie)\
**Post date:** [February 18, 2020, 3:13pm UTC](https://discuss.elastic.co/t/compare-fields-of-different-documents-in-the-same-index/219756/2 "2020-02-18T15:13:50Z")

</div>

It sounds like you want to explore individual documents with filters that you don't know ahead of time. Can you add filters in Discover? For example, `Field1.value: "Value1"` is a query you could run. If you want to provide a nicer UI for this, you could save your Discover search and embed it into a dashboard, and then add an Input Controls widget.

---

<div class="post-metadata">

**Author:** ![JamieUnix](https://avatars.discourse-cdn.com/v4/letter/j/71e660/32.png) [@JamieUnix](https://discuss.elastic.co/u/JamieUnix)\
**Post date:** [February 19, 2020, 3:14pm UTC](https://discuss.elastic.co/t/compare-fields-of-different-documents-in-the-same-index/219756/3 "2020-02-19T15:14:17Z")

</div>

Thank you Wylie.  
But let me try to explain my problem more clearly. Below is a simplified structure of my docs.  
**Index1**  
**Doc** 1 (ingested by source1)  
Field1 = "ABC"  
Field2 = "DEF"  
**Doc** 2 (ingested by source2)  
field1 = "ABC"  
field2 = "EDF"  
**Doc** 3 (ingested by source1)  
Field1 = "GHI"  
Field2 = "JKL"  
**Doc** 4 (ingested by source2)  
field1 = "GHI"  
field2 = "JL"  
Now, I want to loop through all the different field1.value values(docs ingested by source2) and find all the docs (ingested by source1) if field1.value==Field1.value.  
Is this even possible in kibana?

---

<div class="post-metadata">

**Author:** ![wylie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wylie/32/81794_2.png) [@wylie](https://discuss.elastic.co/u/wylie)\
**Post date:** [February 19, 2020, 3:37pm UTC](https://discuss.elastic.co/t/compare-fields-of-different-documents-in-the-same-index/219756/4 "2020-02-19T15:37:20Z")

</div>

I don't really understand this use case, but because it needs to run in two passes you have limited options:

1. The only client-side way to run two passes in Kibana is using Canvas. You can make a request, and then script something to make another request
2. In a batch process, you can set a field like `doc.hasMatching: true` in documents and then use this in Kibana
3. You might be able to do this using a [Continuous Transform](https://www.elastic.co/guide/en/elasticsearch/reference/current/transforms.html)

---

<div class="post-metadata">

**Author:** ![JamieUnix](https://avatars.discourse-cdn.com/v4/letter/j/71e660/32.png) [@JamieUnix](https://discuss.elastic.co/u/JamieUnix)\
**Post date:** [February 20, 2020, 6:59am UTC](https://discuss.elastic.co/t/compare-fields-of-different-documents-in-the-same-index/219756/5 "2020-02-20T06:59:10Z")

</div>

Thank you and I will look into your options

---

<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:** [March 19, 2020, 6:59am UTC](https://discuss.elastic.co/t/compare-fields-of-different-documents-in-the-same-index/219756/6 "2020-03-19T06:59:19Z")

</div>

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