愚者求师之过,智者从师之长。

bool 查询请教

Elasticsearch | 作者 ridethewind | 发布于2019年03月21日 | 阅读数:1301

如下代码片段所示,有没有办法可以做到,如果我查“123456“这个term存在就直接返回,而不去查下面的两个match_phrase,若“123456“这个term的结果不存在,则用match_phrase去查123和456?
{
"query": {
"bool":{
"filter":{
"bool":{
"should":
[
{"term" : { "text" :"123456" }},
{
"bool":{
"must":[
{"match_phrase" : { "text" :"123" }},
{"match_phrase" : { "text" :"456" }}
]
}
}
]
}
}
}
}
}
已邀请:

laoyang360 - 《一本书讲透Elasticsearch》作者,Elastic认证工程师 [死磕Elasitcsearch]知识星球地址:http://t.cn/RmwM3N9;微信公众号:铭毅天下; 博客:https://elastic.blog.csdn.net

赞同来自:

1 text应该是text.keyword吧
2 text确认能分词为 123 456,用的什么分词,analyzer api验证下

要回复问题请先登录注册