Using Exact Prefix/MatchPhrase Prefix Queries with Ngram Filter

Hi,
My goal is to search query text having length one or two character long.
This is my setting for the index.

"settings" : {
      "index" : {
        "number_of_shards" : "5",
        "provided_name" : "my_user",
        "analysis" : {
          "filter" : {
            "ngrammed" : {
              "type" : "ngram",
              "min_gram" : "3",
              "max_gram" : "50"
            }
          },
          "analyzer" : {
            "ngrammed_ci" : {
              "filter" : [
                "lowercase",
                "ngrammed"
              ],
              "type" : "custom",
              "tokenizer" : "standard"
            },
            "keyword_ci" : {
              "filter" : [
                "lowercase"
              ],
              "type" : "custom",
              "tokenizer" : "keyword"
            }
          }
        }
      }
    }

I have a set of users with a display name field with the following analyzers. Say if I have a couple of users with names like
Allen, Alec, Kimball, Polly
The problem I am facing is that when I search with a 2 character length query string like al along with Allen & Alec, it matches with Kimball as well since the ngram filter tokenizes Kimball as all in the inverted index. I am trying to avoid this scenario. Also wanted to know if there is anyway to implement this functionality without changing anythin on the Index side of things and make the changes only for query side.

"user_display_name" : {
  "type" : "text",
  "fields" : {
    "ci" : {
    "type" : "text",
    "analyzer" : "keyword_ci"
    }
  "cs" : {
    "type" : "keyword"
    }
  },
  "analyzer" : "ngrammed_ci",
  "search_analyzer" : "standard"
}

sounds like you are more interested in so called edge_ngrams than ngrams.

That said, maybe you can also make use of the search as you type datatype, which can probably save you some setup woes here and works out of the box.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.