Search with Nest not yielding expected results

I am creating an index with the following code:

    	var ElasticSettings = new ConnectionSettings(new Uri(ConnectionString))
                            .DefaultIndex(_IndexName)
			.DefaultMappingFor<PictureObject>(M => M
				.Ignore(_ => _._id)
				.Ignore(_ => _.Log))
                                    .DefaultFieldNameInferrer(_ => _);

		_ElasticClient = new ElasticClient(ElasticSettings);

		if (!_ElasticClient.IndexExists(_IndexName).Exists)
		{
			var I = _ElasticClient.CreateIndex(_IndexName, Ci => Ci
				.Settings(S => S
					.Analysis(A => A
						.CharFilters(Cf => Cf.Mapping("expressions",
							E => E.Mappings(ExpressionsList))
						)
						.TokenFilters(Tf => Tf.Synonym("synonyms",
							Descriptor => new SynonymTokenFilter
							{
								Synonyms = SynonymsList,
								Tokenizer = "whitespace"
							})
						)
						.Analyzers(Analyzer => Analyzer
							.Custom("index", C => C
								.CharFilters("expressions")
								.Tokenizer("standard")
								.Filters("synonyms", "standard", "lowercase", "stop")
							)
							.Custom("search", C => C
								.CharFilters("expressions")
								.Tokenizer("standard")
								.Filters("synonyms", "standard", "lowercase", "stop")
							)
						)
					)
				)
				.Mappings(Mapping => Mapping
					.Map<PictureObject>(Map => Map
						.AutoMap()
						.Properties(P => P
							.Text(T => T
								.Name(N => N.Title)
								.Analyzer("index")
								.SearchAnalyzer("search")
							)
							.Text(T => T
								.Name(N => N.Tags)
								.Analyzer("index")
								.SearchAnalyzer("search")
							)
						)
					)
				)
			);

The fields I want to search are 'title' and 'tags'

My synonyms are in that format:
[
"big => large, huge",
"small => tiny, minuscule",
]

and my expressions are like:
[
"stormy weather => storm",
"happy day => joy",
]

When I do a search, I have tried these two methods:

var Test1 = _ElasticClient.Search<PictureObject>(S => S
			.From(From)
			.Size(Take)
		        .Query(_ => _.Fuzzy(Fuzz => Fuzz.Field(F => F.Tags).Field(T => T.Title).Value(Terms).MaxExpansions(2)))).Documents;

var resTest2 = _ElasticClient.Search<PictureObject>(S => S
			.Query(_ => _.QueryString(F => F.Query(Terms)))
			.From(From)
			.Size(Take));

When trying to match terms exactly as they are in the tags field, the two functions return different results.
When trying to use synonyms, results vary again.

What am I missing?

Hi @ThomasD3,

do you observe the same behaviour when using the REST endpoint directly? Asking because if this is not a specific NEST client question, you might find more people able to help. If you can reproduce the issue you are having also via REST (e.g. in the Kibana Console), could you post a miniature index, your analysis settings and mappings and the above query in JSON format for easier reproduction?

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