lucene - Using wildcard and required operator in an Elasticsearch search -


we have various rows inside our elasticsearch index contain text

"... 2% milk ...".

user enters query "2% milk" search field , transform internally query

title:(+milk* +2%*) 

because terms should required , possibly interested rows contain "2% milkfat".

this query above return 0 hits. changing query

title:(+milk* +2%) 

returns reasonable results. why '*' operator in first query not work?

unless set mapping, "%" sign removed in tokenization process. "2% milk" turned tokens 2 , milk.

when search "2%*" looks tokens like: 2%, 2%a, 2%b, etc... , not match indexed tokens, giving no hits.

when search "2%", go through same tokenization process @ index-time (you can specify this, default tokenization same) , looking documents matching token 2, give hit.

you can read more analysis/tokenization process here , can set analysis want defining custom mapping

good luck!


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -