jolicode / elastically

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

Fix index name mapper getting pure index name frome alias #91

Closed kennywick closed 2 years ago

kennywick commented 2 years ago
damienalexandre commented 2 years ago

Thanks a lot for your contribution!

If I understand your change correctly, the idea is to support indices that don't have a date in their name? Is that because the indices are not created via Elastically?

kennywick commented 2 years ago

If I understand your change correctly, the idea is to support indices that don't have a date in their name? Is that because the indices are not created via Elastically?

In part yes (that's what we're doing in our integration tests), but also to support getting an index by its alias. Let's take an example of an index todo with prefix foo

$index = $client->getIndex('todo'); 

//This would be 'foo_todo'
$index->getName();

//Then we want to migrate the index
$indexBuilder->migrate($index);

So in the IndexBuilder::migrate() function

        //This currently returns 'foo_todo' instead of 'todo'
        $pureIndexName = $this->indexNameMapper->getPureIndexName($currentIndex->getName());

        //This is now passed the prefixed Index name instead of the pure index name
        $newIndex = $this->createIndex($pureIndexName);

This then expects a mapping file that is named foo_todo_mapping.yaml instead of the existing todo_mapping.yaml

damienalexandre commented 2 years ago

Thanks a lot @kennywick :+1: