我有一个简单对象的弹性索引,它有两个字段:
{
"content": "something",
"acl": ["andrey", "gilles"]
}
acl
字段是用户名数组或值“public”,或者根本不存在于对象中。我想写一个查询,它给我acl=testuser
或不存在的所有对象。这是我的问题:
{
"query": {
"bool": {
"should": [
{
"bool" : {
"must": [
{"exists" : { "field" : "acl" }},
{"match" : {"acl":"testuser"}}
]
},
"bool": {
"must_not": [
"exists": {
"field": "acl"
}
]
}
}
]
}
}
}
但是当我执行它时,我收到一个错误:
{
"error": {
"root_cause": [
{
"type": "parsing_exception",
"reason": "[bool] malformed query, expected [END_OBJECT] but found [FIELD_NAME]",
"line": 12,
"col": 11
}
],
"type": "parsing_exception",
"reason": "[bool] malformed query, expected [END_OBJECT] but found [FIELD_NAME]",
"line": 12,
"col": 11
},
"status": 400
}
任何想法我做错了什么?
答案 0 :(得分:1)
您的JSON无效:
const bcrypt = require('bcrytpjs');
查询bool
should
是一个数组,您没有为新对象添加花括号此外,您不需要must_not
查询与exist
查询匹配。因此,您只需将match
查询和match
must_not
查询留在exist
内,如下所示:
should