# AND operator in dis\_max queries

**URL:** <https://discuss.elastic.co/t/and-operator-in-dis-max-queries/111867>\
**Category:** Elasticsearch\
**Created:** [December 14, 2017, 10:08pm UTC](https://discuss.elastic.co/t/and-operator-in-dis-max-queries/111867 "2017-12-14T22:08:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![AnnaM](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/annam/32/25498_2.png) [@AnnaM](https://discuss.elastic.co/u/AnnaM)\
**Post date:** [December 14, 2017, 10:08pm UTC](https://discuss.elastic.co/t/and-operator-in-dis-max-queries/111867/1 "2017-12-14T22:08:21Z")

</div>

Is it possible to define that the conditions in dis\_max queries should use AND operator instead OR ( Elasticsearch 5.6.2) ?  
For my example I want to see only the results which contains ".31319.67121." as "hierarchyPath" value AND "/quarterly-results/2016/q4/" in "indexableTaxonomyTags" value :

```auto
"query": {
"bool": {
"must": [{
"dis_max": {
"queries": [{
"match": {
"hierarchyPath": {
"type": "phrase_prefix",
"query": ".31319.67121."
}
}
}, {
"match": {
"indexableTaxonomyTags": {
"type": "phrase_prefix",
"query": "/quarterly-results/2016/q4/"
}
}
}
]
}
}, {
"range": {
"startPublish": {
"lte": "2017-12-13T11:30:04.0238794+01:00"
}
}
}
]

```

---

<div class="post-metadata">

**Author:** ![mayya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mayya/32/83147_2.png) [@mayya](https://discuss.elastic.co/u/mayya)\
**Post date:** [December 28, 2017, 5:18pm UTC](https://discuss.elastic.co/t/and-operator-in-dis-max-queries/111867/2 "2017-12-28T17:18:27Z")

</div>

No, in `dis_max` there is no way to force all subqueries to match.  
Is there any particular reason you use `dis_max`?  
Why don't put all your three clauses under a single `must` which will satisfy your requirement:

```
  "query": {
	"bool": {
		"must": [
			{
				"match": {"hierarchyPath": {"type": "phrase_prefix", "query": ".31319.67121."}}
			}, 
			{
				"match": {"indexableTaxonomyTags": {"type": "phrase_prefix", "query": "/quarterly-results/2016/q4/"}}
		    }, 
	        {
	        	"range": {"startPublish": {"lte": "2017-12-13T11:30:04.0238794+01:00"}}
	        }
        ]
    }
}
```

---

<div class="post-metadata">

**Author:** ![AnnaM](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/annam/32/25498_2.png) [@AnnaM](https://discuss.elastic.co/u/AnnaM)\
**Post date:** [January 8, 2018, 1:20pm UTC](https://discuss.elastic.co/t/and-operator-in-dis-max-queries/111867/3 "2018-01-08T13:20:03Z")

</div>

You are totally right. Using the "must" works fine.  
In meantime I have found another solution - just to use the filter instead  
\</\>

1. "filter": [
2. 

```
 	    {

```

3. 

```
 			"prefix": {

```

4. 

```
 				"hierarchyPath": {

```

5. 

```
 					"value": ".31319.67121."

```

6. 

```
 				}

```

7. 

```
 			}

```

8. 

```
 		},

```

9. 

```
 		{

```

10. 

```
				"prefix": {

```

11. 

```
					"indexableTaxonomyTags": {

```

12. 

```
						"value": "/quarterly-results/2016/q4/"

```

13. 

```
					}

```

14. 

```
				}

```

15. 

```
			}

```

16. 

```
]

```

\</\>  
My main mistake was to use wrong mapping definition for this fields. Its need "analyzer": "keyword" .  
Many thanks

---

<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:** [February 5, 2018, 1:20pm UTC](https://discuss.elastic.co/t/and-operator-in-dis-max-queries/111867/4 "2018-02-05T13:20:05Z")

</div>

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