gpt4 book ai didi

php - ElasticSearch查询格式错误。 Elastic-PHP客户端

转载 作者:行者123 更新时间:2023-12-03 00:46:11 24 4
gpt4 key购买 nike

我正面临导致查询出现故障的问题。我的查询如下

 $params = [
'index'=>'us_data_master',
'body' => [
'query' => [
'bool'=>[
'must'=>[
"terms" => [
"city_code" => [
"Los Angeles",
"Aguara Hills",
]
],
[
"term"=>['state_code'=>'CA']
],
'multi_match'=>[
'query'=>'*app*',
'fields'=>['name','contact_no','zip_code','city_code']
]
],
"must_not"=>[
"term"=>["contact_no"=>"0"]
]
]
]
]
];

它返回错误为
"error":{"root_cause":[{"type":"parsing_exception","reason":"[terms] malformed query, expected [END_OBJECT] but found [FIELD_NAME]","line":1,"col":65}],"type":"parsing_exception","reason":"[terms] malformed query, expected [END_OBJECT] but found [FIELD_NAME]","line":1,"col":65},"status":400} 

我也已经安装了Kibana,那里的查询工作完美。我正在尝试将其复制到PHP客户端,但它给了我错误。 Kibana中的工作查询如下
  {
"query": {
"bool": {
"must": [
{
"terms": {
"city_code.keyword": [
"Los Angeles",
"Aguara Hills"
]
}
},
{
"term": {
"state_code.keyword": "CA"
}
},
{
"multi_match": {
"query": "*appliance*",
"fields": ["name","city_code","address","contact_no"]
}
}
],
"must_not": [
{
"term": {
"contact_no.keyword": "0"
}
}
]
}
}
}

最佳答案

您似乎在Terms Query后错过了方括号,并且还存在其他格式问题,但是我相信以下查询应能为您提供帮助:

$params = [
'index'=>'us_data_master',
'body' => [
'query' => [
'bool'=>[
'must'=>[
[
'terms' => [
'city_code.keyword' => [ 'Los Angeles', 'Aguara Hills' ]
]
],
[
'term'=>['state_code.keyword'=>'CA']
],
[
'multi_match'=>[
'query'=>'*app*',
'fields'=>['name','contact_no','zip_code','city_code']
]
]
],
'must_not'=>[
[
'term'=>['contact_no.keyword'=>'0']
]
]
]
]
]
];

希望这可以帮助!

关于php - ElasticSearch查询格式错误。 Elastic-PHP客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60783124/

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