Fri*_*ian 4 php search elasticsearch
我有一个页面,允许用户查询数据集并应用过滤器。他们还可以在不使用字符串查询的情况下应用过滤器。为此,我尝试将 match_all 与过滤器一起使用,但出现以下错误
"{"error":{"root_cause":[{"type":"parsing_exception","reason":"[match_all] 格式错误的查询,预期为 [END_OBJECT] 但找到 [FIELD_NAME]","line":1," col":26}],"type":"parsing_exception","reason":"[match_all] 格式错误的查询,预期为 [END_OBJECT] 但发现 [FIELD_NAME]","line":1,"col":26}, "状态":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
]
]
Run Code Online (Sandbox Code Playgroud)
我似乎无法弄清楚如何使用它们。任何指针?谢谢你。
您需要将查询包装在这样的bool查询中:
"query": {
"bool" : {
"must" : {
"match_all": {}
},
"filter": {
"range" : { /* your filter here*/ }
}
}
}
Run Code Online (Sandbox Code Playgroud)
只需将bool和 一个must查询包裹在您的周围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
]
]
Run Code Online (Sandbox Code Playgroud)
如需参考,请参阅文档Elasticsearch Reference [7.0] » Query DSL » Compound queries » Bool Query,它包含一个像你这样的例子,match_all并结合了过滤器。
| 归档时间: |
|
| 查看次数: |
2582 次 |
| 最近记录: |