[英]Combine two queries in one request
我想通過一個請求在elasticsearch服務器上執行多個查詢。 具體來說,我有以下查詢(在elastcisearch-php-client上)
$params = [
"index" => "bookydate",
"type" => "vendor_service",
"body" => [
"query" => [
"bool" => [
"must" => [
"term" => [
"sys_service_id" => $request->input("sys_service_id")
]
],
"should" => [
"geo_shape" => [
"served_location" => [
"shape" => [
"type" => "point",
"coordinates" => [
"{$request->input('loc_lon')}",
"{$request->input('loc_lat')}"]
]
]
]
]
]
]
]
];
我想做的是還獲取所有具有"hole_country"
字段為true
的文檔。
我已經嘗試過的是向Elasticsearch服務器發出另一個請求,並使用array_merge
合並兩個結果,但是由於PHP對具有多個相同鍵的數組的限制而無法正常工作。
UPDATE
Elastcisearch支持一項名為Multisearch
的功能,這正是我正在尋找的功能。 問題是php客戶端不支持多重搜索,因此我必須使用Guzzle才能發送請求。
Guzzle docs沒有有關如何構造正確的請求正文的完整信息。 歡迎任何信息
我已經具有以下主體,但elastcisearch正在重試錯誤的請求錯誤
$body = [
["index"=>"bookydate"],
["query"=>["bool"=> ["must"=>[["term"=>["sys_service_id"=>"1"]],["geo_shape"=>["served_location"=>["shape"=>["type"=>"circle","coordinates"=>[25,3],"radius"=>"90km"]]]]]]]],
["index"=>"bookydate"],
["query"=>["bool"=>["must"=>["term"=>["hole_country"=>true]]]]]
];
您可以使用Elasticsearch的multisearch API。 這或多或少在單個POST請求中將所有查詢作為JSON格式追加。 我希望PHP客戶端支持此功能,否則您可能必須手動執行POST請求。
盡管未記錄,但Elasticsearch php客戶端支持Multi Search API 。
而不是search
調用msearch
,並按以下方式對查詢進行分組: $params = [ 'body' => [ ["index" => "bookydate", "type" => "vendor_service"], ["query" => [ "bool" => [ "must" => [ "term" => [ "sys_service_id" => $request - > input("sys_service_id") ] ], "should" => [ "geo_shape" => [ "served_location" => [ "shape" => [ "type" => "point", "coordinates" => [ "{$request->input('loc_lon')}", "{$request->input('loc_lat')}" ] ] ] ] ] ] ]] ];
因此,使用更新后的語法是正確的。 您必須致電msearch 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.