# Compare two fields with different documents

**URL:** https://discuss.elastic.co/t/compare-two-fields-with-different-documents/311529
**Category:** Logstash
**Created:** [August 5, 2022, 12:40pm UTC](https://discuss.elastic.co/t/compare-two-fields-with-different-documents/311529 "2022-08-05T12:40:34Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![alex\_vermex](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alex_vermex/32/101267_2.png) [@alex\_vermex](https://discuss.elastic.co/u/alex_vermex)
#### Post date: [August 5, 2022, 12:40pm UTC](https://discuss.elastic.co/t/compare-two-fields-with-different-documents/311529/1 "2022-08-05T12:40:34Z")

</div>

Hi,  
I want to compare two fields but not in the same document is that possible ?  
for example :

```auto
if date.document1 == date.document2 and x.document1 == y.document2 {
    #DO somthing
}

```

Any help would be sincerely appreciate!  
Thanks!

---

<div class="post-metadata">

### Author: ![alex\_vermex](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alex_vermex/32/101267_2.png) [@alex\_vermex](https://discuss.elastic.co/u/alex_vermex)
#### Post date: [August 5, 2022, 12:50pm UTC](https://discuss.elastic.co/t/compare-two-fields-with-different-documents/311529/2 "2022-08-05T12:50:47Z")

</div>

I will try to explain more I want for a new document I want to compare it with all the documents I have or something like that if i found `date.document1 == date.document2 and x.document1 == y.document2 then #DO somthing`

---

<div class="post-metadata">

### Author: ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)
#### Post date: [August 5, 2022, 1:12pm UTC](https://discuss.elastic.co/t/compare-two-fields-with-different-documents/311529/3 "2022-08-05T13:12:52Z")

</div>

It is not clear what you want to do, can you provide more context and a real example?

What do you want to do after comparing it? Are the documents being ingested or they already exist in Elasticsearch?

You want to compare fields from different events in logstash? Or you want to compare documents that are in elasticsearch but using a Logstash pipeline?

---

<div class="post-metadata">

### Author: ![alex\_vermex](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alex_vermex/32/101267_2.png) [@alex\_vermex](https://discuss.elastic.co/u/alex_vermex)
#### Post date: [August 5, 2022, 1:33pm UTC](https://discuss.elastic.co/t/compare-two-fields-with-different-documents/311529/4 "2022-08-05T13:33:11Z")

</div>

i have two files i read these files using filebeat so i extract each log with multiline.pattern then i send the data to kafka so the logstash entry is kafka...

For file1, for example I have two fields "date,code", so I want to compare it with other documents, I mean the "documents in file2" if I found the date and code are the same in this document, then send me an e-mail. i am sending data from two files in the same index to compare it so this is what i mean with `date.document1 == date.document2 and x.document1 == y.document2 then #send email`

I hope you understand me

---

<div class="post-metadata">

### Author: ![alex\_vermex](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alex_vermex/32/101267_2.png) [@alex\_vermex](https://discuss.elastic.co/u/alex_vermex)
#### Post date: [August 5, 2022, 1:49pm UTC](https://discuss.elastic.co/t/compare-two-fields-with-different-documents/311529/5 "2022-08-05T13:49:44Z")

</div>

logstash.conf

```auto
filter {
if ("kafka-topic-file1" in [topic_name]) {
# i created a fields using grok with regular expression 
# example fields : date1, code1
}
if("kafka-topic-file2" in [topic_name]) {
# i created a fields using grok with regular expression 
# example fields : date2, code2
}
output {
if ([date1] == [date2] and [code1] == [code2]) {
# send e-mail ( i did it it works )
}

```

doesn't work because as I understand I can't compare two fields with different documents and I ask if there is a solution for this.

I hope you understand me @leandrojmp and Thanks \<3

---

<div class="post-metadata">

### Author: ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)
#### Post date: [August 5, 2022, 1:59pm UTC](https://discuss.elastic.co/t/compare-two-fields-with-different-documents/311529/6 "2022-08-05T13:59:45Z")

</div>

This is not possible with Logstash.

Every event is independent from each other, you can't compare different events.

---

<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: [September 2, 2022, 2:00pm UTC](https://discuss.elastic.co/t/compare-two-fields-with-different-documents/311529/7 "2022-09-02T14:00:28Z")

</div>

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