# Compare fields value

**URL:** https://discuss.elastic.co/t/compare-fields-value/311387
**Category:** Logstash
**Created:** [August 4, 2022, 9:02am UTC](https://discuss.elastic.co/t/compare-fields-value/311387 "2022-08-04T09:02:45Z")
**Posts on this page:** 4
**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 4, 2022, 9:02am UTC](https://discuss.elastic.co/t/compare-fields-value/311387/1 "2022-08-04T09:02:45Z")

</div>

Hi,  
I would like if it is possible how to compare this value of two fields

- field1 : 123456XXXXXX1234
- field2 : 1234567890001234

I mean i want to do if first 6 chars and last 4 chars of field1 are similar to field2 then add mutate or do something...

Any help would be sincerely appreciate!  
Thanks!

---

<div class="post-metadata">

### Author: ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)
#### Post date: [August 4, 2022, 4:09pm UTC](https://discuss.elastic.co/t/compare-fields-value/311387/2 "2022-08-04T16:09:00Z")

</div>

You would need to extract those characters and then compare them. I have not tested this but perhaps

```
grok {
    break_on_match => false
    match => {
        "[field1]" => "^(?<[@metadata][field1][start].{6}).*(?<[@metadata][field1][end]>.{4})$"
        "[field2]" => "^(?<[@metadata][field2][start].{6}).*(?<[@metadata][field2][end]>.{4})$"
    }
}
if [@metadata][field1][start] == [@metadata][field2][start] and [@metadata][field1][end] == [@metadata][field2][end] {
    # Do something
}

```

---

<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, 2:12pm UTC](https://discuss.elastic.co/t/compare-fields-value/311387/3 "2022-08-05T14:12:53Z")

</div>

It works if these two fields in the same documents yes but in my case these two fields are not in the same document 😕 i created a [new topic](https://discuss.elastic.co/t/compare-two-fields-with-different-documents/311529) for this

---

<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:13pm UTC](https://discuss.elastic.co/t/compare-fields-value/311387/4 "2022-09-02T14:13:15Z")

</div>

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