在Elasticsearch php API中使用多个类型或索引

Ram*_*min 8 php api search types elasticsearch

我想使用Elasticsearch PHP API查询多个类型和索引.但我不知道怎么做.我应该传递一系列类型和索引$params吗?:

$params['index'] = $index;//array of indices
$params['type']  = $types;//array of types
$params['body']  = $q;//query body
//request elasticsearch for matched documents
$results = $client->search($params);
Run Code Online (Sandbox Code Playgroud)

Ram*_*min 11

您只需将它们作为字符串添加到$params:

$params['index'] = "index1, index2";//array of indices
$params['type']  = "type1, type2";//array of types
$params['body']  = $q;//query body
//request elasticsearch for matched documents
$results = $client->search($params);
Run Code Online (Sandbox Code Playgroud)

  • 我知道这很老了,但是我遇到的问题是……非常重要的是,索引值的逗号后面不能有空格!它将崩溃。 (2认同)