Skip to content

Elasticsearch deprecation #5446

@dannyvw

Description

@dannyvw

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
)]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions