jolicode / elastically

🔍 JoliCode's Elastica wrapper to bootstrap Elasticsearch PHP integrations
248 stars 37 forks source link

Search in multiple indices #51

Closed JochenRousse closed 3 years ago

JochenRousse commented 3 years ago

Hi,

I was looking for a way to run a search query in more than one index at the same time. From what I've seen, this does not seem possible at the moment with Elastically, do you have any plans on implementing this feature in the framework ?

damienalexandre commented 3 years ago

Actually you can already but the API is not obvious.

        $search = $client->getIndex('post')->createSearch();
        $search->addIndex('comment');
        $search->addIndex('foobar');
        $search->setQuery($searchQuery);

The ResultSetBuilder will hydrate the correct DTO for each index found in the results.

Can you have a try?

JochenRousse commented 3 years ago

Thank you for the quick reply, I'll give it a try !

JochenRousse commented 3 years ago

Update: it worked like a charm. Thank you very much @damienalexandre!