Partial word search does not work with Ngram Analyzer!

Despairly trying to add n-gram to an index but no effect! I try dozen combination but still does not have partial word matching!

            ICreateIndexResponse indexResult = await _elasticClient.CreateIndexAsync("product", p => p
            .Mappings(m => m.Map<ProductDetailModel>(c => c.AutoMap()))    
            .Settings(setting => setting
                        .TokenFilters(t => t.NGram("nGram", ng => ng.MinGram(2).MaxGram(2)))
                        .Analyzers(an => an
                             .Custom("test", ca => ca
                                 .Tokenizer("standard")
                                 .Filters("nGram" )
                        )
                    )
                 )
               )
            );

Here is the query

{
  "query": {
       "match" : { "name" : "gra" } 
  }
}

Thanks in advance

On the basis of what you've provided, a custom analyzer is set up to use the nGram token filter, but this analyzer is not being used for any of the fields on ProductDetailModel or anywhere else in the index.

Take a look at the documentation on writing analyzers for how to hook up the analyzer to a field.

1 Like

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