Matchme php script_PHP-使用match_all和过滤器

我有一个页面,允许用户查询数据集并应用过滤器.他们还可以应用过滤器而无需查询字符串.为此,我尝试将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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值