Problem with Arrays in Elastic Search

Hello,

So, I am writing a custom autocomplete using elastic search.

Version 2.X . Assume the following mapping.

"country" : {
       "type" : "string",
       "analayzer" : "patternAnalyzer" //Split by commas
       "fields" : {
          "typeahead" : {
              "type" : "string"
              "analyzer" : "customAnalyzer"  //Split by commas & then apply n-gram (n=3)
        }
    }
}

The data I would have is something like below:

{
     "country" : "United States of America , Canada"
}

The problem I have is when I try to find a matching ngram when the user types 'states'. I only expect to get 'United States of America' in my suggestions and not 'Canada'. Now I get both in autocomplete suggestions. (since the ngrams of USA and Canada are stored together).
Is there a way to accomplish this?

Maybe someway by which the ngrams still somehow know which string they are n-grams of. (Currently I have to do a explicit pattern match on results to make sure to remove non matching ones)

Thanks in advance!

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