Search code examples
ruby-on-railselasticsearchsearchkick

Searchkick - Elasticsearch - Names with underscore instead of white space


we have tags example:

hello_my_name_is

Tag.search "hello"
=> []

But when trying to search for hello with searchkick/elasticsearch we dont get anything in the results. We explicitly need to search for hello_my_name_is in order to get it.

Tag.search "hello_my_name_is"
=> [{name: "hello_my_name_is"...}]

Is there some way to get around this issue?


Solution

  • ElasticSearch cares about what type of search you're performing. In this case, the default is a match of the entire word. One way to solve your problem would be to use the partial matches functionality of the searchkick gem.

    Tag.search "hello", fields: [:name], match: :word_start
    

    Don't forget to reindex after you make your changes.