【发布时间】:2020-12-08 10:48:04
【问题描述】:
我是 elasticSearch 和嵌套的新手。在一个 c# 项目中,我使用 Nest 将数据查询到 elasticSearch 数据库。我无法控制数据库(我无法在此处添加多字段或指定分析器)。 我有一个文本字段,它的值可以是“Some-Thing_A”或“Some-Thing_B”或“Other”等,但总是类似关键字的值。我想查询它的确切字符串(由用户给出)“Some-Thing_A”。 我正在使用以下查询:
var searchResponse = client.Search<LogData>(s =>
s.Index("indexxx")
.Size(50)
.Query(q =>
q.Match(m => m.Field(f => f.Branche).Query("Some-Thing_A")))));
可能返回“Some-Thing_A”或“Some-Thing_B”...
我尝试过使用“术语”,但它不起作用。 我尝试使用这样的分析器:
client.Indices.Create("indexxx", c => c.Map<LogData>(m => m.AutoMap()));
var searchResponse = client.Search<LogData>(s =>
s.Index("indexxx")
.Size(50)
.Query(q => q
.Match(m => m.Field(f => f.Branche).Analyzer("keyword").Query("Some-Thing_A"))
);
在我的 LogData 类中:
[Text(Name = "Branche", Analyzer = "keyword", SearchAnalyzer ="keyword", Index = true)]
public string Branche { get; set; }
但它总是返回 0 命中。我错过了什么 ?有没有办法使用关键字分析器而无需访问数据库来更改它?
【问题讨论】:
标签: c# elasticsearch nest