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);

1 Answer 1

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);
Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.