在我的Elastic中,我有这样的条目:AB-001-123-B
当运行带有match_phrase_prefix的查询时,如下所示:
"query": {
"bool": {
"should": [
{
"match_phrase_prefix": {
"code": "AB-00"
}
}
]
}
},
...
字符串
我没有得到任何结果。将代码更改为
"query": {
"bool": {
"should": [
{
"match_phrase_prefix": {
"code": "AB-001"
}
}
]
}
},
...
型
它返回条目。当从代码中删除-00
时,它也会返回该条目。
我对其他条目做了几次测试。当搜索短语以0结尾时,他似乎无法查询。
为什么会这样?有没有办法在查询中解决这个问题?我试过逃跑,没有任何效果。
1条答案
按热度按时间wljmcqd81#
code
字段是由standard
分析器分析的text
字段。这意味着AB-001-123-B
被分析为以下标记:字符串
match_phrase_prefix
并不适合您的用例。最好使用prefix
查询来查询code.keys
字段,如下所示:型