How to get elasticsearch to execute similar SQL 'LIKE'

If using the SQL operator "Like" to query data, it will return data, even if they only partially match. For example, if I am looking for food, and there is an element in my db called "raisins" when using SQL, the query returns "raisins", even if my search contains only "rai". In elasticsearch, the request will not return a record if the full name is not specified (in this case, "highlight"). How can I make elasticsearch behave similarly to the SQL statement. I am using Rails 3.1.1 and PostgreSQL. Thanks!

+7
source share
1 answer

When creating a model index for elasticsearch, use a tokenizer in the index that will meet your requirement. For. eg.

tokenizer: { :name_tokenizer => {type: "edgeNGram", max_gram: 100, min_gram: 3, side: "front"} } 

this will create markers ranging in size from 3 to 100 of your margins and, since the side will be indicated as the front, it will be checked from the beginning. You can get more details from here http://www.slideshare.net/clintongormley/terms-of-endearment-the-elasticsearch-query-dsl-explained

+5
source

All Articles