我有一个页面,允许用户查询数据集并应用过滤器.他们还可以应用过滤器而无需查询字符串.为此,我尝试将match_all与过滤器配合使用,但出现以下错误
“{“error”:{“root_cause”:[{“type”:”parsing_exception”,”reason”:”[match_all]
malformed query, expected [END_OBJECT] but found
[FIELD_NAME]”,”line”:1,”col”:26}],”type”:”parsing_exception”,”reason”:”[match_all]
malformed query, expected [END_OBJECT] but found
[FIELD_NAME]”,”line”:1,”col”:26},”status”:400}”,
这是我正在构建并发送给弹性客户端的搜索参数的示例.
[
"type" => "events"
"index" => "events"
"body" => [
"query" => [
"match_all" => {}
"bool" => [
"filter" => [
"range" => [
"start_date.date" => [
"gte" => "01/05/2019"
"lte" => "05/2019"
"format" => "dd/MM/yyyy||MM/yyyy"
]
]
]
]
]
"from" => 0
"size" => 30
]
]
我似乎无法弄清楚如何同时使用它们.有指针吗?谢谢.
解决方法:
您将需要将查询包装在布尔查询中,如下所示:
"query": {
"bool" : {
"must" : {
"match_all": {}
},
"filter": {
"range" : { /* your filter here*/ }
}
}
}
只需将布尔值和必须查询周围的match_all包起来,它就可以工作.
我不知道确切的PHP语法,但是应该是这样的:
[
"type" => "events"
"index" => "events"
"body" => [
"query" => [
"bool" => [
"must" => [ "match_all" => {}]
"filter" => [
"range" => [
"start_date.date" => [
"gte" => "01/05/2019"
"lte" => "05/2019"
"format" => "dd/MM/yyyy||MM/yyyy"
]
]
]
]
]
"from" => 0
"size" => 30
]
]
标签:elasticsearch,search,php
来源: https://codeday.me/bug/20191210/2104758.html