我对elasticsearch有错误:
“query_parsing_exception:期望[END_OBJECT]但获得[FIELD_NAME], 可能有太多查询子句“
我使用带有PHP的elasticsearch,这是我的搜索:
$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'],
]
];
请问有什么问题?
答案 0 :(得分:2)
每个range
查询必须位于其自己的数组元素中,并且所有bool/must
查询必须包含在数组中。你可以这样做:
$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'],
]
];