# Comparing the different document field values

**URL:** https://discuss.elastic.co/t/comparing-the-different-document-field-values/224165
**Category:** Elasticsearch
**Created:** [March 18, 2020, 5:51pm UTC](https://discuss.elastic.co/t/comparing-the-different-document-field-values/224165 "2020-03-18T17:51:16Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![mussa572](https://avatars.discourse-cdn.com/v4/letter/m/a698b9/32.png) [@mussa572](https://discuss.elastic.co/u/mussa572)
#### Post date: [March 18, 2020, 5:51pm UTC](https://discuss.elastic.co/t/comparing-the-different-document-field-values/224165/1 "2020-03-18T17:51:17Z")

</div>

Hi  
Just wondering How can I compare the value from 2 different documents . I am ingesting the following values in the index.

I am looking to query and compare of each document field "type\_instance" value of "allocated-mb" \> "max-mb" of the each plugin\_instance .

```
POST test/_bulk
{"index":{"_id":1}}
{"plugin_instance": "root-yarn-queue-name-1", "type_instance": "allocated-mb", "value": 4024}
{"index":{"_id":2}}
{ "plugin_instance": "root-yarn-queue-name-1", "type_instance": "max-mb", "value": 2048}
{"index":{"_id":3}}
{"plugin_instance": "root-yarn-queue-name-2", "type_instance": "max-mb", "value": 3048}
{"index":{"_id":4}}
{"root-yarn-queue-name-2", "type_instance": "allocated-mb", "value": 1028}
{"index":{"_id":5}}
{"plugin_instance": "some-random-queue-name-2", "type_instance": "allocated-mb", "value": 2028}
{"index":{"_id":6}}
{"plugin_instance": "some-random-queue-name-2", "type_instance": "max-mb", "value": 2028}

```

* * *

just wonder what would the easy way to achieve following

1. Select records with plugin\_instance=root-yarn-queue-name-\*
2. select records with type\_instance in (allocated-mb, allocated-vcores, max-mb, max-vcores)
3. group records with same plugin\_instance (to get records for a queue in a bucket)
4. compare if value of allocated-mb \> max-mb and allocated-vcore \> max-vcore  
and select those records which fulfil all these conditions in a given time period

till now I have managed to bucket the document based on the plugin\_instance . Wondering what would be the easy way to compare the documents of each bucket based on the "type\_instance"

```
    GET test/_search
    {
      "query": {
        "query_string": {
          "default_field": "plugin_instance.keyword",
          "query": "root-yarn-queue-name-*"
        }
      },
      "aggs": {
        "byField": {
          "terms": {
            "field": "plugin_instance.keyword"
          }
         
        }
      }
    }
```

---

<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: [April 15, 2020, 5:51pm UTC](https://discuss.elastic.co/t/comparing-the-different-document-field-values/224165/2 "2020-04-15T17:51:22Z")

</div>

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