I have documents in my Elasticsearch index like tihs:
{ "id": 1, "text": "My document text", "field1": "value1", "field2": "value2" }
I need to support:
- A user entered query string that should search the "text" field. (No problem)
- Unaware to the user, I need to add a filter that essentially says: "WHERE field1=value1 OR field2=value2".
This second requirement is causing me problems. In my boolean query, I am trying to add a filter query that consists of a dis_max query. So like this:
{ "query": { "bool": { "filter": [ "constant_score": { "filter": { "dis_max": { "tie_breaker": 0.0, "queries": [ { "match": { "field1": { "query": "value1", "operator": "OR", "prefix_length": 0, "max_expansions": 50, "fuzzy_transpositions": true, "lenient": false, "zero_terms_query": "NONE", "boost": 1.0 } } }, { "match": { "field2": { "query": "value2", "operator": "OR", "prefix_length": 0, "max_expansions": 50, "fuzzy_transpositions": true, "lenient": false, "zero_terms_query": "NONE", "boost": 1.0 } } } ] } } } ] //Filters array } } }
But it appears I am getting the dis_max query AND'ing those two queries together instead of OR'ing so I do not get enough results.
Is using a dis_max query in a filter the proper way to achieve this type of behavior?