-
-
Notifications
You must be signed in to change notification settings - Fork 934
Description
API Platform version(s) affected: 3.1
Description
To avoid index calls to ES for doctrine entities on cache build you can define elasticsearch: false
on your ApiResource which is documented in https://api-platform.com/docs/core/elasticsearch/#creating-models and added in #5177 but this triggers this deprecation https://github.com/api-platform/core/blob/main/src/Elasticsearch/Metadata/Resource/Factory/ElasticsearchProviderResourceMetadataCollectionFactory.php#L53
Only on false a no index call is performed https://github.com/api-platform/core/blob/main/src/Elasticsearch/Metadata/Resource/Factory/ElasticsearchProviderResourceMetadataCollectionFactory.php#L101. So not sure how we can fix this deprecation?
Also the index name in hasIndices is now from the shortName, but should it not something like this?
$options = $operation->getStateOptions() instanceof Options ? $operation->getStateOptions() : new Options(index: $this->getIndex($operation));
try {
$this->client->cat()->indices(['index' => $options->getIndex() ?? $this->getIndex($operation)]);
return true;
} catch (Missing404Exception|NoNodesAvailableException) {
return false;
}
private function getIndex(Operation $operation): string
{
return Inflector::tableize($operation->getShortName());
}
How to reproduce
#[ApiResource(
elasticsearch: false
)]