Find model with part of title using ElasticSearch / Rails -


there following post model:

class post < activerecord::base   include elasticsearch::model   include elasticsearch::model::callbacks      def self.search query       __elasticsearch__.search(         {             query: {                 multi_match: {                     query: query,                         fields: ['title']                 }             },                 filter: {                      and: [                         { term: { deleted: false } },                         { term: { enabled: true } }                     ]                 }         }       )     end      settings index: { number_of_shards: 1 }       mappings dynamic: 'false'         indexes :title, analyzer: 'english'       end     end end  post.import 

i have 1 post 'amsterdam' title. when execute post.search('amsterdam') 1 record, good. if execute post.search('amster') no records. wrong? how can fix it? thanks!

os - os x, elasticsearch installed using homebrew

you have use ngram tokenizer, in order create partial text search. example of how can found here. said, careful ngram, can turn unrelated results.

this because substring "mon" contained within of strings: "monkey", "money", , "monday". of unrelated.

alternatively (what do.)

you try making fuzzy search. however, max distance fuzzy search two, still doesn't return in example. however, tends return relevant results.

the example found: how use fuzzy search

# perform fuzzy search! post /fuzzy_products/product/_search {   "query": {     "match": {       "name": {         "query": "vacuummm",         "fuzziness": 2,         "prefix_length": 1       }     }   } } 

Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -