Search code examples
ruby-on-railselasticsearchsearchkick

How to match incomplete terms in Elasticsearch using Searchkick?


I'm using Elasticsearch + Searchkick in my Rails app to index articles. When I search using incomplete words, it does not work. For example:

Article.search('feature compatibility').pluck(:name)
# => ["Feature compatibility by mobile device"]

Article.search('feature compatibil').pluck(:name)
# => []

My model uses the default Searchkick settings.


Solution

  • First add this to your model (word_start not text_start)

    searchkick word_start: [:name, :body]
    

    Then you need to delete the index, recreate it and reindex your data. After that your search queries will work as expected