# While searching how do I exclude only one object and include other object inside a nested object

**URL:** <https://discuss.elastic.co/t/while-searching-how-do-i-exclude-only-one-object-and-include-other-object-inside-a-nested-object/327322>\
**Category:** Elasticsearch\
**Tags:** eql-elastic-query-language\
**Created:** [March 9, 2023, 6:26am UTC](https://discuss.elastic.co/t/while-searching-how-do-i-exclude-only-one-object-and-include-other-object-inside-a-nested-object/327322 "2023-03-09T06:26:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nabin\_Upreti](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nabin_upreti/32/118234_2.png) [@Nabin\_Upreti](https://discuss.elastic.co/u/Nabin_Upreti)\
**Post date:** [March 9, 2023, 6:26am UTC](https://discuss.elastic.co/t/while-searching-how-do-i-exclude-only-one-object-and-include-other-object-inside-a-nested-object/327322/1 "2023-03-09T06:26:05Z")

</div>

I want to search minimum of the negotiated\_rate where negotiated type is not percentage. I used must not query to filter out percentage but this results to excluding the whole document.  
Here I expect the minimum negotiated\_rate to be 20.(from the second document)

Below are the 2 sample documents in my index:

```
    "_source": {
      "billing_code": "11602",
	  "proc_details": [
        {
          "negotiated_rate": 400,
          "negotiated_type": "fee schedule", 
        },
        {
          "negotiated_rate": 262,
          "negotiated_type": "fee schedule",
        }
      ],
      }

```

{  
"\_source": {  
"billing\_code": "11602",  
"proc\_details": [  
{"negotiated\_rate": 100,  
"negotiated\_type": "percentage",  
},  
{  
"negotiated\_rate": 20,  
"negotiated\_type": "fee schedule",  
}  
],  
},  
}

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [March 19, 2023, 11:51pm UTC](https://discuss.elastic.co/t/while-searching-how-do-i-exclude-only-one-object-and-include-other-object-inside-a-nested-object/327322/2 "2023-03-19T23:51:49Z")

</div>

Hi @Nabin_Upreti

Have you tried using aggregation to retrieve the smallest value negotiated\_rate?

---

<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 16, 2023, 11:52pm UTC](https://discuss.elastic.co/t/while-searching-how-do-i-exclude-only-one-object-and-include-other-object-inside-a-nested-object/327322/3 "2023-04-16T23:52:32Z")

</div>

Closed on April 16, 2023, 11:52pm UTC

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