[英]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.