不为失败找理由,要为成功找方法。

es nested 根据多条件排除数据

Elasticsearch | 作者 yangcj | 发布于2021年05月28日 | 阅读数:2728

es,kibana  6.5
{
list:[{id:1,amount:0},{id:2,amount:1},{id:1,amount:1}]
},
{
list:[{id:1,amount:0},{id:2,amount:1},{id:1,amount:0}]
}


数据类型如上,当前希望排除id=1,且所有amount =0的数据,根据上面的情况仅返回第一条
{
list:[{id:1,amount:0},{id:2,amount:1},{id:1,amount:1}]
}
因为存在{id:1,amount:1} 不符合条件,所以保留,请问各位有什么思路或建议吗?
 
-----
 
我的思路是
{
"query": {
"bool": {
"must": [
{
"nested": {
"path": "list",
"query": {
"bool": {
"must_not": [
{
"term": {
"list.id": {
"value": 1
}
}
},
{
"term": {
"list.amount": {
"value": 0
}
}
}
]
}
}
}
}
]
}
}
}
但是感觉不起效, 不知道有没有人有什么想法
已邀请:

simaGang - 90 php

赞同来自:

请问有答案了吗,我也遇到这个问题了
 

dachuxing

赞同来自:

nested 查询,must_not 得放在外部

1653039329862.jpg

 

要回复问题请先登录注册