在没有访问 ElasticSearch 数据库的情况下对文本字段使用 Nest Analyzer "keyword"
Using Nest Analyzer "keyword" on text Field without access to ElasticSearch DB
我是 elasticSearch 和 nest 的新手。在 c# 项目中,我使用 Nest 将数据查询到 elasticSearch 数据库。我无法控制数据库(我无法在此处添加多字段或指定分析器)。
我有一个文本字段,它可以有像“Some-Thing_A”或“Some-Thing_B”或“其他”等值,但总是类似关键字的值。我想查询确切的字符串(用户给的)“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")))));
可能 return“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 class 中:
[Text(Name = "Branche", Analyzer = "keyword", SearchAnalyzer ="keyword", Index = true)]
public string Branche { get; set; }
但总是return 0 命中。我错过了什么 ?有没有一种方法可以在不访问数据库的情况下使用关键字分析器从那里进行更改?
在尝试了更多解决方案后,我设法使用了“term”。我不知道弹性动态映射正在映射具有关键字和文本类型的文本字段。
var searchResponse = client.Search<LogData>(s =>
s.Index("indexxx")
.Size(5000)
.Query(q => q.Term(term => term
.Field(field => field.Branche.Suffix("keyword"))
.Value("Some-Thing_A")))
.Sort(srt => srt
.Ascending(p => p.Timestamp))
);
我是 elasticSearch 和 nest 的新手。在 c# 项目中,我使用 Nest 将数据查询到 elasticSearch 数据库。我无法控制数据库(我无法在此处添加多字段或指定分析器)。 我有一个文本字段,它可以有像“Some-Thing_A”或“Some-Thing_B”或“其他”等值,但总是类似关键字的值。我想查询确切的字符串(用户给的)“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")))));
可能 return“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 class 中:
[Text(Name = "Branche", Analyzer = "keyword", SearchAnalyzer ="keyword", Index = true)]
public string Branche { get; set; }
但总是return 0 命中。我错过了什么 ?有没有一种方法可以在不访问数据库的情况下使用关键字分析器从那里进行更改?
在尝试了更多解决方案后,我设法使用了“term”。我不知道弹性动态映射正在映射具有关键字和文本类型的文本字段。
var searchResponse = client.Search<LogData>(s =>
s.Index("indexxx")
.Size(5000)
.Query(q => q.Term(term => term
.Field(field => field.Branche.Suffix("keyword"))
.Value("Some-Thing_A")))
.Sort(srt => srt
.Ascending(p => p.Timestamp))
);