我正在尋找ElasticSearch嵌套查詢將提供精確匹配的字符串中使用C#中的空格。彈性搜索搜索字符串中使用C#空格和特殊字符#
例如 - 我想搜索一個詞,如'XYZ公司解決方案'。我試過查詢字符串查詢,但它給我所有的記錄,不論搜索結果如何。另外我在帖子上閱讀,發現我們必須爲該領域添加一些映射。我在該領域嘗試了'Not_Analyzed'分析儀,但仍然無效。
這裏是我的C#
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")));** //this gives 0 records
**ISearchResponse<dynamic> ivals1 = objElasticClient.Search<dynamic>(s => s.Index(elastic_newindexname).AllTypes().Query(q => q.Term(u => u.OnField("Name").Value("XYZ Company Solutions"))));** //this gives 0 records
**ISearchResponse<dynamic> ivals = objElasticClient.Search<dynamic>(s => s.Index(elastic_newindexname).AllTypes().Query(@"Name = 'XYZ Company Solutions'"));** //this gives all records having fields value starting with "XYZ"
代碼如果有人有完整的例子或在C#中的步驟,然後可以請您與我分享?
還可以提供越做越elasticsearch創建了索引架構? curl -XGET localhost:9200/name_of_the_index?pretty = true 基本上,爲了匹配確切的字符串,您需要確保在索引時不分析它。 –