jolicode / elastically

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

Allow index refreshing with prefixed index name #87

Closed darthf1 closed 2 years ago

darthf1 commented 3 years ago

Hi!

I don't like to pass my ES mapping around in various classes, so I make extensive use of

$client->getIndexNameFromClass($object::class)

This returns the prefixed index name for a specific class.

After indexing, I want to manually refresh the index:

$indexer = $client->getIndexer();
$indexer->scheduleIndex(
    $client->getIndexNameFromClass($object::class),
    new Document((string) $object->getId(), $object)
);
$indexer->flush();

### refresh below
$indexer->refresh('unprefixed_index_name');

The issue I'm having with the refresh function, is that it needs the unprefixed index name, because it will prepend this index name with the prefix.

refresh(): https://github.com/jolicode/elastically/blob/v1.3.0/src/Indexer.php#L119 calls getIndex() https://github.com/jolicode/elastically/blob/v1.3.0/src/Client.php#L71 which unconditionally adds the prefix.

However, (as far as I can see) there's no way to get the unprefixed index name from a class. But it would be even better, if I can just pass the prefixed index name to the refresh function.

Korbeil commented 3 years ago

Hey, We could even get rid of getIndexNameFromClass, the idea is to make a is_class check on the string and if it's true (so it's a DTO), then we get the index name from the mapping and if it's false, we use the actual method (based on index alias or true name).

darthf1 commented 3 years ago

Hey, We could even get rid of getIndexNameFromClass, the idea is to make a is_class check on the string and if it's true (so it's a DTO), then we get the index name from the mapping and if it's false, we use the actual method (based on index alias or true name).

Yeah even better

damienalexandre commented 2 years ago

Maybe #91 fixed that issue.

damienalexandre commented 2 years ago

I will consider this issue fixed as you don't provide more feedback :+1: thanks for the report!