elasticsearch - 当它们是“AND-OR”条件时如何使用弹性搜索获取数据(查询生成器)
问题描述
例如,如果我必须从所有文件“(userId OR currentUserId) AND (customeromerId OR customercode OR customerbacth) AND (customerph or customer addrss) AND customercity”的文本匹配中获取结果。
如果我使用下面的代码,我将得到根据关键字匹配的结果,而不管AND
OR
条件如何。
$queryMsg = ['query_string' => ['query' => $query]];
但是我想获取结果,例如,应该获取与 userId 或 currentUserId 和 customeromerId 匹配的记录。
请帮助我如何在弹性搜索中编写查询,以便我可以获取结果。
提前非常感谢。
解决方案
{
"query" : {
"must" : [
{
"bool" : {
"should" : [
{
"match" : {'userId' : id}
},
{
"match" : {'currentUserId' : id}
}
],
"minimum_should_match" : 1
}
},
{
"bool": {
"should": [
{
"match": {'customeromerId': code}
},
{
"match": {'customercode': code}
},
{
"match": {'customerbacth': code}
}
],
"minimum_should_match" : 1
},
},
{
"bool": {
"should": [
{
"match": {'customerph': address}
},
{
"match": {'customer addrss': address}
}
],
"minimum_should_match" : 1
}
},
{
"bool" : {
"must" : {
"customercity" : city
}
}
}
]
}
}
推荐阅读
- elasticsearch - Elasticsearch - 文本类型正则表达式
- python - Line Magics - PyCharm 中未解决的引用
- jquery - 异步加载内容不会减慢网站加载时间
- gstreamer - 构建 Gstreamer 编辑服务失败
- python - 如何在python中将RGB图像转换为直线?
- php - 单击按钮时,我想将所有数据从我的表移动到另一个表
- html - 如何在 Html 中编写可点击的电话号码,这是没有国家代码的本地号码
- python - Python Popen() 的问题(语法?)
- python - 在python中间接排序列表
- algorithm - Geeksforgeeks 在提交后将我的代码显示为运行时错误