我正在使用elastichsearch 5来存储和搜索一些文档。
在我的文档中,我有一个名为URL的字段,如下所示:
{
//... other fields
"URL": "http://ip:8080/app/addItemToCart.html?workingItemId=X1"
}
我试图对通配符使用查询,因为我想获取URL中包含单词“addItemToCart”的所有文档。
这是我的查询:
GET myindex/_search
{
"query" : {
"wildcard" : { "URL" : "*addItemToCart*" }
}
}
它返回零个文档,但我在带有该关键字的elasticsearch中有文档。
这是我对索引的映射。
GET myindex/_mapping
{
//.... other fields
"URL": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
怎么了?
最佳答案
如in the documentation所述,通配符查询
Matches documents that have fields matching a wildcard expression (not analyzed)
因此,您的查询应为:
GET myindex/_search
{
"query" : {
"wildcard" : { "URL.keyword" : "*addItemToCart*" }
}
}
关于elasticsearch - Elasticsearch中带有斜杠的通配符返回零条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55169355/