AND operator in dis_max queries

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 :

"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"
}
}
}
]

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"}}
	        }
        ]
    }
}
1 Like

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

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