gpt4 book ai didi

php - 预期[END_OBJECT],但获得了[FIELD_NAME]

转载 作者:行者123 更新时间:2023-12-03 00:59:07 25 4
gpt4 key购买 nike

我对elasticsearch有一个错误:

"query_parsing_exception: expected [END_OBJECT] but got [FIELD_NAME], possibly too many query clauses"



我在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'],
]
];

请问是什么问题?

最佳答案

每个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'],
]
];

关于php - 预期[END_OBJECT],但获得了[FIELD_NAME],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40284870/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com