# How to compare two fields of same name on different doc\_type

**URL:** https://discuss.elastic.co/t/how-to-compare-two-fields-of-same-name-on-different-doc-type/215860
**Category:** Elasticsearch
**Created:** [January 21, 2020, 10:36am UTC](https://discuss.elastic.co/t/how-to-compare-two-fields-of-same-name-on-different-doc-type/215860 "2020-01-21T10:36:02Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![vimal](https://avatars.discourse-cdn.com/v4/letter/v/d2c977/32.png) [@vimal](https://discuss.elastic.co/u/vimal)
#### Post date: [January 21, 2020, 10:36am UTC](https://discuss.elastic.co/t/how-to-compare-two-fields-of-same-name-on-different-doc-type/215860/1 "2020-01-21T10:36:02Z")

</div>

Hi,  
I have two oracle tables containing millions of rows in each table. I have index all records into elasticsearch using logstash jdbc plugin.

The Idea is to compare difference between two tables using Elasticsearch in fast manner. Faster than SQL.

I have index called myindex and two documents type table1 and table2.

I have to compare column1 of table1 document type with column1 of table2 document type.

How can it be achieved in elastic search?

---

<div class="post-metadata">

### Author: ![pastechecker](https://avatars.discourse-cdn.com/v4/letter/p/0ea827/32.png) [@pastechecker](https://discuss.elastic.co/u/pastechecker)
#### Post date: [January 21, 2020, 10:57am UTC](https://discuss.elastic.co/t/how-to-compare-two-fields-of-same-name-on-different-doc-type/215860/2 "2020-01-21T10:57:53Z")

</div>

You can do it on the logstash itself.

For example you will write a filter section:

```auto
filter {
if [table1] == [table2]{
mutate {
add_field => {"field_equality" => "field_is_the_same"}
}
}
else {
mutate {
add_field => {"field_equality" => "field_is_not_the_same"}
}
}
}

```

Test:

```auto
input { stdin { codec => json}}

filter {
        if [table1] == [table2]{
                mutate {
                        add_field => {"field_equality" => "field_is_the_same"}
                }
        }
        else {
                mutate {
                        add_field => {"field_equality" => "field_is_not_the_same"}
                }
        }
}

output { stdout { codec => rubydebug}}

TEST DATA: {"table1": "table1", "table2": "table2"}
OUTPUT:
{
        "@timestamp" => 2020-01-21T10:56:59.429Z,
              "host" => "srv-cdc0058.phenom.semicon.io",
    "field_equality" => "field_is_not_the_same",
          "@version" => "1",
            "table2" => "table2",
            "table1" => "table1"
}

TEST DATA: {"table1": "table1", "table2": "table1"}
OUTPUT: 
{
        "@timestamp" => 2020-01-21T10:57:14.431Z,
              "host" => "srv-cdc0058.phenom.semicon.io",
    "field_equality" => "field_is_the_same",
          "@version" => "1",
            "table2" => "table1",
            "table1" => "table1"
}

```

Is it what you wanted or i misunderstood your question?  
If not, please share some data example.

---

<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: [February 18, 2020, 10:57am UTC](https://discuss.elastic.co/t/how-to-compare-two-fields-of-same-name-on-different-doc-type/215860/3 "2020-02-18T10:57:54Z")

</div>

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