8

I want to query multiple types and indices using Elasticsearch PHP API. but I don't Know how. should I pass an array of types and indices to $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);
Ramin Omrani
  • 3,673
  • 8
  • 34
  • 60

1 Answers1

12

You just add them as a string to $params :

$params['index'] = "index1,index2";// a comma-separated list of index names, without any extra space
$params['type']  = "type1, type2";//array of types
$params['body']  = $q;//query body
//request elasticsearch for matched documents
$results = $client->search($params);
Ovinz
  • 453
  • 5
  • 11
Ramin Omrani
  • 3,673
  • 8
  • 34
  • 60
  • 4
    I know this is old, but something I just ran into with this is... it is VERY important you do not have a space after the comma in index value! It'll just crash it. – Tim Habersack Jun 07 '18 at 23:34