Elasticsearch string query match multiple term of one field Elasticsearch string query match multiple term of one field elasticsearch elasticsearch

Elasticsearch string query match multiple term of one field


Your queries are fine. Both should work:

"_type:server_physical AND cpu:*2620* AND cpu:*E5* AND cpu:*v3*""_type:server_physical AND cpu:(*2620* AND *E5* AND *v3*)"

The trick lies in one of the string query parameters lowercase_expanded_terms. It defaults to true and lowercases all the characters that are part of wildcards i.e. your E5 becomes e5. Try setting it to false and all should work:

POST index/_search{    "query": {        "query_string": {           "query": "_type:server_physical AND cpu:(*2620* AND *E5* AND *v3*)",           "lowercase_expanded_terms": false        }    }}

Bonus edit: why does it work without cpu:? Because by default query string will then do a search on the _all field (unless you disabled it), which is a concatenation of all your fields in the document. It then gets analyzed and if you don't specify the analyzer the default one will be used which lowercases (among other things) all the terms in the _all field hence it would contain e5 not E5.