elasticsearch - 弹性搜索结合匹配和应该
问题描述
我想创建一个可以使用匹配的查询,并且该匹配应该只考虑另一个字段值为空或某个特定值的行。
所以像:
where field1 like 'string' and field2 is null or field2 = 123
JS客户端有可能吗?
解决方案
您可以结合使用bool/must/should
存在和通配符查询
{
"query": {
"bool": {
"must": [
{
"wildcard": {
"field1": "string*"
}
},
{
"bool": {
"should": [
{
"term": {
"field2": 123
}
},
{
"bool": {
"must_not": {
"exists": {
"field": "field2"
}
}
}
}
]
}
}
]
}
}
}
推荐阅读
- java - 根据条件合并两个列表并使用 java 8 将结果推送到地图
- protractor - 错误:在 config.yml 文件上 ng e2e -- --protractor-config=./e2e/protractor-ci.conf.js 时生成 chromedriver
- php - 集成 CCAVENUE 支付网关时面临的问题
- c# - “违反主键约束'...'。无法在对象中插入重复键
- google-sheets - 如何使用带有公式的新行并被视为空行
- c++ - 访问类的功能不起作用
- pine-script - 如何更改 Y 轴上的货币?
- kubernetes - Kubernetes IP 冲突
- javascript - 如何在 js 或 jquery 中制作 CTRL + '+'
- c++ - std::set 必须存储树的根吗?