I am looking for an ElasticSearch nest query that will ensure an exact match of a string containing spaces in it using C #.
for example - I want to find a word, for example, "XYZ Company Solutions". I tried the query with the query, but it gives me all the records regardless of the search result. I also read in the post and found that we need to add some mappings for the field. I tried the "Not_Analyzed" analyzer on the field, but still it did not work.
Here is my C # code
var indexDefinition = new RootObjectMapping { Properties = new Dictionary<PropertyNameMarker, IElasticType>(), Name = elastic_newindexname }; var notAnalyzedField = new StringMapping { Index = FieldIndexOption.NotAnalyzed }; indexDefinition.Properties.Add("Name", notAnalyzedField); objElasticClient.DeleteIndex(d => d.Index(elastic_newindexname)); var reindex = objElasticClient.Reindex<dynamic>(r => r.FromIndex(elastic_oldindexname).ToIndex(elastic_newindexname).Query(q => q.MatchAll()).Scroll("10s").CreateIndex(i => i.AddMapping<dynamic>(m => m.InitializeUsing(indexDefinition)))); ReindexObserver<dynamic> o = new ReindexObserver<dynamic>(onError: e => { }); reindex.Subscribe(o);** **ISearchResponse<dynamic> ivals = objElasticClient.Search<dynamic>(s => s.Index(elastic_newindexname).AllTypes().Query(q => q.Term("Name","XYZ Company Solutions")));**
If anyone has a complete example or steps in C #, can you share with me?
source share