concept47
concept47

Reputation: 31796

search not returning matches I want with ngram filter

My elastic search setup is something like this

         :analyzer => {
            :default => {
              :type => "custom",
              :tokenizer => "whitespace",
              :filter => ["lowercase", "standard", "my_ngram"]
            }
          }

where my_gram is specified like this

            :my_ngram => {
              :type => "nGram",
              :min_gram => 1,
              :max_gram => 20
            }

The problem is that when I search for something like "cre" im getting "crib" as a result as well as "crew" and "remember" ... which appears like its matching on 're' and 'cr' ... I want it to be an exact match for 'cre' inside the word if there is a match.

what am I doing wrong?

Upvotes: 0

Views: 238

Answers (1)

concept47
concept47

Reputation: 31796

Found the answer to this ... just specify :default_operator => AND in the query_string options. So something like this (using Tire gem, because I'm lazy)

    Post.search do
      query { string your_query_string_here, :default_operator => "AND" }
    end

Upvotes: 1

Related Questions