[英]how to user query should and must_not in elasticseacrh
i have data in elastic like this我有这样的弹性数据
{
"xId" : "25b35718-1804-428e-87fc-e215422d21a0",
"date" : "2019-10-13T07:07:07.558Z",
"type" : "promo",
"accountId" : 50,
"readBy" : [
"b",
"a"
]
}
I want to retrieve data with a number of conditions , so i use query with should and must_not, when I use that query, the array returns empty, but now the data still appears, is there something missing?我想检索具有多个条件的数据,所以我使用带有 should 和 must_not 的查询,当我使用该查询时,数组返回空,但现在数据仍然出现,是否缺少某些内容?
this is my sample query这是我的示例查询
{"query": {
"constant_score": {
"filter": {
"bool": {
"should": [
{
"terms": {
"accountId": [50]
}
},{
"terms": {
"type": ["promo"]
}
},
{
"match": {
"userId": "a"
}
}
],
"must_not": [
{
"terms": {
"type": []
}
}, {
"terms": {
"readBy": ["a"]
}
}
]
}
}
}
}
}
solved i use query like this解决了我使用这样的查询
{"query": {
"constant_score": {
"filter": {
"bool": {
"should": [
{
"terms": {
"accountId": [50]
}
},{
"terms": {
"type": ["promo"]
}
},
{
"match": {
"userId": "a"
}
}
],
"must_not": [
{
"terms": {
"type": []
}
}, {
"term": {
"readBy.keyword": "a"
}
}
]
}
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.