# How does must work's for multiple query with in array and in filter if there is null value(for query) then automatically remove that query

**URL:** <https://discuss.elastic.co/t/how-does-must-works-for-multiple-query-with-in-array-and-in-filter-if-there-is-null-value-for-query-then-automatically-remove-that-query/238394>\
**Category:** Elasticsearch\
**Created:** [June 24, 2020, 7:06am UTC](https://discuss.elastic.co/t/how-does-must-works-for-multiple-query-with-in-array-and-in-filter-if-there-is-null-value-for-query-then-automatically-remove-that-query/238394 "2020-06-24T07:06:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![akshaybhuradia](https://avatars.discourse-cdn.com/v4/letter/a/67e7ee/32.png) [@akshaybhuradia](https://discuss.elastic.co/u/akshaybhuradia)\
**Post date:** [June 24, 2020, 7:06am UTC](https://discuss.elastic.co/t/how-does-must-works-for-multiple-query-with-in-array-and-in-filter-if-there-is-null-value-for-query-then-automatically-remove-that-query/238394/1 "2020-06-24T07:06:16Z")

</div>

```auto
{
	"query": {
    	"bool":{
    		"must": [{"match" : { "userid" : "001" } }, {"query_string" : {"fields":["searchbar_content"],"query" : "*"} } ],
    		"filter":[
		    			{ "terms" : { "tag" : ["tag yesterday"] } },
		    			{ "range": { "craetedon":{ "gte":"now-12M" ,"lt":"now" } } } 
    			     ]
    	}
    }
}

```

let suppose there are multiple record correspond to userid.

userid is written first and string query second in must array.

**First case :**  
does must first search for all record correspond to userid and then find filter out query result in above case. or userid and query string both take together and find result.

**Second Case :**  
let suppose user does not give any tag value or createdon value or both

```auto
    		"filter":[
		    			{ "terms" : { "tag" : ["null"] } },
		    			{ "range": { "craetedon":{ "gte":"now-12M" ,"lt":"now" } } } 
    			     ]

```

then filter automatically remove this query and filter like(after null)

```auto
   		"filter":[
		    			{ "range": { "craetedon":{ "gte":"now-12M" ,"lt":"now" } } } 
    			     ]

```

**Second case for filter :**

```auto
   		"filter":[
		    			{ "terms" : { "tag" : ["tagg"] } },
		    			{ "range": { "craetedon": {null} } } 
    			     ]
    		"filter":[
		    			{ "terms" : { "tag" : ["tagg"] } }
    			     ]

```

**Third case for filter:**  
if userid and created are null then no filter

```auto
{
	"query": {
    	"bool":{
    		"must": [{"match" : { "userid" : "001" } }, {"query_string" : {"fields":["searchbar_content"],"query" : "*"} } ]
}}}

```

![image](https://us1.discourse-cdn.com/elastic/original/3X/3/2/3276720014d790aaeda5834632a03b87bca8bc75.png)  
i want to develop gmail like search one search bar (string query)  
and filter if user left blank field then this field should be remove as i said earlier.

---

<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:** [July 22, 2020, 7:06am UTC](https://discuss.elastic.co/t/how-does-must-works-for-multiple-query-with-in-array-and-in-filter-if-there-is-null-value-for-query-then-automatically-remove-that-query/238394/2 "2020-07-22T07:06:29Z")

</div>

Closed on July 22, 2020, 7:06am UTC

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