# Facing issues with searching ES with 3 where clauses or filters

**URL:** <https://discuss.elastic.co/t/facing-issues-with-searching-es-with-3-where-clauses-or-filters/180504>\
**Category:** Elasticsearch\
**Created:** [May 10, 2019, 7:08am UTC](https://discuss.elastic.co/t/facing-issues-with-searching-es-with-3-where-clauses-or-filters/180504 "2019-05-10T07:08:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vishal\_Gupta1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vishal_gupta1/32/42108_2.png) [@Vishal\_Gupta1](https://discuss.elastic.co/u/Vishal_Gupta1)\
**Post date:** [May 10, 2019, 7:08am UTC](https://discuss.elastic.co/t/facing-issues-with-searching-es-with-3-where-clauses-or-filters/180504/1 "2019-05-10T07:08:56Z")

</div>

Hi , I want to query ElasticSearch with 3 filters and then take the sum of the "value" of all returned records.

My search criteria is explained below:

Include --\> Fetch records matching the "valueOfColumn1" in Column1  
Include --\> Filter only records matching the "valueOfColumn2" in Column2  
Exclude --\> Filter out (remove) the records matching the "valueOfColumn3" in Column3

I have created below query but it is not working correctly and no records are being fetched. Could someone help what is incorrect in this query and let me know the correct way to do the query

client.Search(s =\> s.Aggregations(a =\> a.Sum(  
SumOfValues, sm =\> sm.Field(f =\> f.Value)  
)  
).Query(q =\> q.Terms(  
c =\> c.Name(queryKey).Field(  
p =\> p.Column1  
).Terms(valueOfColumn1)  
)  
&& q.Bool  
(b =\> b  
.Must(  
bs =\> bs.Term(p =\> p.Column2, "valueOfColumn2")  
)  
.MustNot(  
bs =\> bs.Term(p =\> p.Column3, "valueOfColumn3")  
)  
)  
)  
);

---

<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:** [June 7, 2019, 7:08am UTC](https://discuss.elastic.co/t/facing-issues-with-searching-es-with-3-where-clauses-or-filters/180504/2 "2019-06-07T07:08:59Z")

</div>

Closed on June 7, 2019, 7:08am UTC

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