# Elasticsearch query\_andvanced\_multi\_match

**URL:** <https://discuss.elastic.co/t/elasticsearch-query-andvanced-multi-match/193471>\
**Category:** Elasticsearch\
**Created:** [August 2, 2019, 7:38am UTC](https://discuss.elastic.co/t/elasticsearch-query-andvanced-multi-match/193471 "2019-08-02T07:38:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Youssfi\_Mohamed](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/youssfi_mohamed/32/51497_2.png) [@Youssfi\_Mohamed](https://discuss.elastic.co/u/Youssfi_Mohamed)\
**Post date:** [August 2, 2019, 7:38am UTC](https://discuss.elastic.co/t/elasticsearch-query-andvanced-multi-match/193471/1 "2019-08-02T07:38:59Z")

</div>

i have an advanced query with elsticsearch. i want to search for all document that mets a specific requirements.  
Document: field1, field2, timestamp  
i have also a list of value for field1 and filed2

listField1=[v1,v2,v3......]  
listField2=[x1,x2,x3......]

i want seach all documents for (field1= v1 and field2=x1) or (field1=v2 and field2=x2)

Can anyone help me?  
the pist that i found is :  
{

```
"query": {
  		
	"bool": {
		"must": [
				{
				"range": {
							"@timestamp":{"from" : "date1", "to" : "date2" }
						}
				}
          
        ],
      
      "should": [
					
                  {
                  		"multi_match": {
                            "query": "v1",
                            "fields": ["field1"]
						}
                  },
                  {
                  			"multi_match": {
                  			"query": "v2",
                  			"fields": ["field1"]
                  			}
                  	}
                  ]
}
}
} 

```

but it need to be more developedPreformatted text

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [August 2, 2019, 8:08am UTC](https://discuss.elastic.co/t/elasticsearch-query-andvanced-multi-match/193471/2 "2019-08-02T08:08:33Z")

</div>

you need a [bool query](https://www.elastic.co/guide/en/elasticsearch/reference/7.2/query-dsl-bool-query.html) with

- a `filter` part, that contains the time range
- a `should` part, that consists of two other bool queries
- each of those `bool` queries have a single `must` part, with two match queries, one for field1 and one for field2

Please take the time to read about the bool query in the docs, as it changes behaviour when you have `must` and `should` clauses.

--Alex

---

<div class="post-metadata">

**Author:** ![Youssfi\_Mohamed](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/youssfi_mohamed/32/51497_2.png) [@Youssfi\_Mohamed](https://discuss.elastic.co/u/Youssfi_Mohamed)\
**Post date:** [August 2, 2019, 8:17am UTC](https://discuss.elastic.co/t/elasticsearch-query-andvanced-multi-match/193471/3 "2019-08-02T08:17:44Z")

</div>

As i understand from your post you mean i put a query like this :

```
{

"query": {
  		
	"bool": {
		"must": [
				{
				"range": {
							"@timestamp":{"from" : "date1", "to" : "date2" }
						}
				}
          
        ],
      
      "should": [
					"bool": {
						"must":{
						
						"multi_match": {
                            "query": "v1",
                            "fields": ["field1"]
						},
						
						"multi_match": {
                            "query": "x1",
                            "fields": ["field2"]
						}
						
							
						}
					},
					"bool": {
						"must":{
						
						"multi_match": {
                            "query": "v2",
                            "fields": ["field1"]
						},
						
						"multi_match": {
                            "query": "x2",
                            "fields": ["field2"]
						}
						
							
						}
					},
                  
                  
				]
}
}
}
```

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [August 2, 2019, 8:40am UTC](https://discuss.elastic.co/t/elasticsearch-query-andvanced-multi-match/193471/4 "2019-08-02T08:40:34Z")

</div>

the top most `must` part should become a `filter` clause

---

<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:** [August 30, 2019, 8:40am UTC](https://discuss.elastic.co/t/elasticsearch-query-andvanced-multi-match/193471/5 "2019-08-30T08:40:35Z")

</div>

Closed on August 30, 2019, 8:40am UTC

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