问题描述
此 nesT 通配符搜索返回零 (0) 个文档,即使它应该返回,因为我的索引中有具有此条件的数据。这是一个有效的连接,设置断点时没有显示错误。有什么想法吗?
public class Book_ES
{
public string book_title { get; set; }
public string book_author { get; set; }
}
sr_detailed = new SearchDescriptor<Book_ES>()
.Index("books_3").Take(10000)
.Query(a => a
.Bool(b => b
.Should(c => c
.Wildcard(d => d
.Field(f=>f.book_title).Field(g=>g.book_author).Value("A*")
)
)
)
).Highlight(h => h.Fields(f => f.Field("*").PreTags("<span class='hit' style='background-color:yellow'>").PostTags("</span>")))
;
var results = Esclient.Search<Book_ES>(sr_detailed);
解决方法
你没有分享你的映射,但我认为它看起来像
TF.js
在这种情况下,当您将 {
"books_3": {
"mappings": {
"properties": {
"book_title": {
"type": "text","fields": {
"keyword": {
"type": "keyword","ignore_above": 256
}
}
},"book_author": {
"type": "text","ignore_above": 256
}
}
}
}
}
}
}
作为通配符查询的值时,您将不会得到任何结果,因为 A*
和 book_title
都使用文本字段的标准分析器并且所有大写字符都从索引标记中删除 - 对于此配置,elasticsearch 不会存储任何以 book_author
开头的标记,见下文
A
您可以在通配符查询中将 GET _analyze
{
"analyzer": "standard","text": "Test"
}
{
"tokens" : [
{
"token" : "test","start_offset" : 0,"end_offset" : 4,"type" : "<ALPHANUM>","position" : 0
}
]
}
设置为 case_insensitive
,这样可以将您的问题解决为 docs say
case_insensitive [7.10.0]在 7.10.0 中添加。 (可选,布尔值)允许 模式与索引字段值的不区分大小写匹配 当设置为 true 时。默认为 false,这意味着区分大小写 匹配取决于基础字段的映射。