Analyzer doesn't work using nest

Hello! I am using elastic with nest for c#.I create analyzers on index time but on search time they don't work.

Here is my class

      public class Car{
      Text(Analyzer = "greek",SearchAnalyzer ="custom",Index = true,IncludeInAll = true)]
      public string SERVICE_DESC { get; set; }
      }

And here is my search query

   var response = client.Search<Nosilia>(n => n
                        .Index(index)
                        .Type(type)
                        .Size(searchSize)
                        .From(0)
                        .TrackScores(true)
                        .Query(q => q
                                     .Match(qs => qs
                                                        .Field(fieldsForSearchList[0])
                                                        .Analyzer("custom")
                                                        .Operator(Operator.And)
                                                        .Query("*"+searchWord+"*"))));

As I mentioned I have already created the two analyzers ("greek","custom")

fields names must be lowercased because elastic tends to lowercase at least their first character, for example SERVICE_DESC gets indexed as sERVICE_DESC. So the most practical solution is to declare it as service_desc.

You can also control how NEST serializes POCO property names to Elasticsearch field names with .DefaultFieldNameInferrer(Func<string, string>) on ConnectionSettings. In this particular case

var settings = new ConnectionSettings(new Uri("http://localhost:9200"))
    .DefaultFieldNameInferrer(s => s);

var client = new ElasticClient(settings);

will use the POCO property names as-is

1 Like

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