我使用ES 7和Laravel实现,我想将范围和术语匹配结合起来,根据文档,我这样做了:
$items = $client->search([
'index' => $instance->getSearchIndex(),
'type' => $instance->getSearchType(),
'body' => [
'size' => 50,
'query' => [
'bool' => [
'must' => [
'multi_match' => [
'fields' => config('elasticsearch.fields'),
'query' => $query,
],
],
'filter' => [
'bool' => [
'must' => [
'range' => [
'note' => [
'gte' => config('elasticsearch.note_minimum')
]
],
'term' => [
'type_video_id' => 5
],
],
],
],
]
],
],
]);
并收到此错误:
“ parsing_exception”,“原因”:“ [范围]格式错误的查询,预期 [END_OBJECT]但找到了[FIELD_NAME]
我只找到了ES 2有关合并查询的文档和示例,是否有所改变?
我希望查询与字段匹配,并根据过滤条件进行过滤。
答案 0 :(得分:1)
这是执行此操作的正确方法:
$items = $client->search([
'index' => $instance->getSearchIndex(),
'type' => $instance->getSearchType(),
'body' => [
'size' => 50,
'query' => [
'bool' => [
'must' => [
'multi_match' => [
'fields' => config('elasticsearch.fields'),
'query' => $query,
]
],
'filter' => [
[
'range' => [
'note' => [
'gte' => config('elasticsearch.note_minimum')
]
]
],
[
'term' => [
'type_video_id' => 5
]
]
]
]
]
]
]);
答案 1 :(得分:0)
我没有办法进行测试,但是我看到几个需要冰壶的支架。另外,您不需要在这些“配置”之前需要$吗?
{
"query" => {
"bool" => {
"must" => [
{
"multi_match" => {
"query" => $query,
"fields" => $config('elasticsearch.fields')
}
}
],
"filter" => {
{
"range" => {
"note" => {
"gte" => $config('elasticsearch.note_minimum')
}
}
},
{
"term" => {
"type_video_id" => {
"value" => "5"
}
}
}
}
}
}
}
如果这不起作用,可以在呈现变量之后粘贴字符串的样子吗?