1
votes

I'm trying to integrate elasticsearch into my symfony application. But I couldn't find any appropriate example on the internet. Now I'm getting this service not found error:

Service "fos_elastica.finder.inscriptions.inscription" not found: even though it exists in the app's container, the container inside "App\Controller\SearchController" is a smaller service locator that only knows about the "doctrine", "form.factory", "http_kernel", "request_stack", "router", "security.authorization_checker", "security.csrf.token_manager", "security.token_storage", "serializer", "session", "templating" and "twig" services. Unless you need extra laziness, try using dependency injection instead. Otherwise, you need to declare it using "SearchController::getSubscribedServices()".

For:

$finder = $this->container->get('fos_elastica.finder.inscriptions.inscription');

As:

Symfony\Component\DependencyInjection\Exception\ ServiceNotFoundException

I don't know how to solve this problem because of insufficient experience with Symfony. Does anyone know how to solve this or any Elasticsearch example with Symfony on the internet? Thanks!

1
You have a lot of examples here for symfony application. Just do ctrl+f symfony.BentCoder

1 Answers

3
votes

In your config/services.yaml file you have to bind this service as argument for your controller like that:

App\Controller\SearchController:
    bind:
        $finder: '@fos_elastica.finder.inscriptions.inscription'

Then you can use it in your controller by injecting it through autowiring:

public function index($finder) {
    // your code here
}

For more information refer to the documentation.