本文介绍了预期[END_OBJECT],但获得了[FIELD_NAME]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
elasticsearch出现错误:
I've an error with elasticsearch :
我在PHP上使用elasticsearch,这是我的搜索:
I use elasticsearch with PHP, this is my search :
$search = [
'index' => $this->getParameter('elastic_search')['index'],
'type' => 'profile',
'body' => [
'query' => [
'bool' => [
'must' => [
'range' => [
'address.latitude' => [
'gte' => $offer->getAddress()->getLatitude() - 0.05,
'lte' => $offer->getAddress()->getLatitude() + 0.05,
],
'address.longitude' => [
'gte' => $offer->getAddress()->getLongitude() - 0.05,
'lte' => $offer->getAddress()->getLongitude() + 0.05,
],
'budget' => [
'gte' => $offer->getPrice() - 100,
'lte' => $offer->getPrice() + 100,
],
],
'bool' => [
"term" => [
"type" => 1
]
]
]
]
],
'from' => $request->get('start', 0),
'size' => $request->get('limit', 4),
'sort' => [],
'_source' => ['exclude' => 'user'],
]
];
请问是什么问题?
推荐答案
每个 range
查询必须位于其自己的数组元素中,并且所有 bool/must
查询都必须包含在内在一个数组中.您可以这样做:
Each range
query must be in its own array element and all bool/must
queries must be enclosed in an array. You can do it like this:
$search = [
'index' => $this->getParameter('elastic_search')['index'],
'type' => 'profile',
'body' => [
'query' => [
'bool' => [
'must' => [
[
'range' => [
'address.latitude' => [
'gte' => $offer->getAddress()->getLatitude() - 0.05,
'lte' => $offer->getAddress()->getLatitude() + 0.05,
]
]
],
[
'range' => [
'address.longitude' => [
'gte' => $offer->getAddress()->getLongitude() - 0.05,
'lte' => $offer->getAddress()->getLongitude() + 0.05,
],
],
],
[
'range' => [
'budget' => [
'gte' => $offer->getPrice() - 100,
'lte' => $offer->getPrice() + 100,
],
],
],
[
"term" => [
"type" => 1
]
]
]
]
],
'from' => $request->get('start', 0),
'size' => $request->get('limit', 4),
'sort' => [],
'_source' => ['exclude' => 'user'],
]
];
这篇关于预期[END_OBJECT],但获得了[FIELD_NAME]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!