Elasticsearch search fails in field with special character and wildcard Elasticsearch search fails in field with special character and wildcard elasticsearch elasticsearch

Elasticsearch search fails in field with special character and wildcard


See the query_string documentation:

Wildcarded terms are not analyzed by default — they are lowercased (lowercase_expanded_terms defaults to true) but no further analysis is done

your stored data is broken up into two terms:

curl -XGET 'localhost:9200/myindex/_analyze?analyzer=diacritical&pretty' -d 'PEI.H.02354.01'{  "tokens" : [ {    "token" : "pei.h",    "start_offset" : 0,    "end_offset" : 5,    "type" : "<ALPHANUM>",    "position" : 1  }, {    "token" : "02354.01",    "start_offset" : 6,    "end_offset" : 14,    "type" : "<NUM>",    "position" : 2  } ]}

but as your search term with a wildcard is only turned into pei.h.02354.01.* it won't match.

however with analyze_wildcard set to true, you do get hits:

curl -XGET "http://localhost:9200/myindex/testType/_search?pretty" -d'> {>    "query":{>       "query_string":{>          "query":"field:PEI.H.02354.01.*",>          "default_operator":"AND",>          "analyze_wildcard": true>       }>    }> }'{  "took" : 5,  "timed_out" : false,  "_shards" : {    "total" : 5,    "successful" : 5,    "failed" : 0  },  "hits" : {    "total" : 2,    "max_score" : 1.4142135,