Migrating from elasticsearch client to Elastica
Hello,
We are trying to migrate from the official elasticsearch client to elastica.
For a first step, we wanted to use a facade for the search method of the official client but using the Elastica\Search behind the scene.
But we are not sure to know what the proper equivalency for some of our older queries.
For example, we have
$data = $this->client->search(
[
'index' => $index,
'_source' => '*',
'sort' => 'updatedAt:desc',
'size' => 10000,
'from' => 0,
'body' => ['query' => ['bool' => ['must' => ['term' => ['statut' => 'published']]]]],
]
We understood from the documentation that we should use
$search = new \Elastica\Search($elasticaClient);
$search->addIndexByName("/" . $index);
for the index
or
$query = new \Elastica\Query(['query' => ['bool' => ['must' => ['term' => ['statut' => 'published']]]]]);
for the body
But it is less clear for the other options. We are confused to how Elastica is managing the options that should/could in the url.
Is there a documentation more precise on this kind of details ?
The documentation on https://elastica.io/ is not too detailed, but I recommend to take a look at the test suite which has lots of examples: https://github.com/ruflin/Elastica/tree/9.x/tests
There are 2 ways how you can use Elastica. Basically as a pass through for the official client or using all the convenience function and objects. For example to do a bool query, you can find an example here: https://github.com/ruflin/Elastica/blob/9.x/tests/Query/BoolQueryTest.php#L23
Instead of writing all the arrays, you can use the classes. And if you use it in the IDE, for most things you should have auto-complete.