# Search with Nest not yielding expected results

**URL:** https://discuss.elastic.co/t/search-with-nest-not-yielding-expected-results/152583
**Category:** Elasticsearch
**Created:** [October 16, 2018, 3:35am UTC](https://discuss.elastic.co/t/search-with-nest-not-yielding-expected-results/152583 "2018-10-16T03:35:54Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![ThomasD3](https://avatars.discourse-cdn.com/v4/letter/t/eb9ed0/32.png) [@ThomasD3](https://discuss.elastic.co/u/ThomasD3)
#### Post date: [October 16, 2018, 3:35am UTC](https://discuss.elastic.co/t/search-with-nest-not-yielding-expected-results/152583/1 "2018-10-16T03:35:55Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)
#### Post date: [October 17, 2018, 9:01am UTC](https://discuss.elastic.co/t/search-with-nest-not-yielding-expected-results/152583/2 "2018-10-17T09:01:26Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [November 14, 2018, 9:01am UTC](https://discuss.elastic.co/t/search-with-nest-not-yielding-expected-results/152583/3 "2018-11-14T09:01:26Z")

</div>

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