[英]ElasticSearch query is malformed. Elastic-PHP Client
我正面臨一個導致查詢出現故障的問題。 我的查詢如下
$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']
]
]
]
]
]
];
希望這可以幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.