jolicode/elastically

Exception when using Symfony HTTP Client

jon-ht opened this issue ยท 3 comments

Hi,

First, thanks for this bundle !

I'm trying to create my first index with HTTP Client but it throws me an exception

php bin/console app:elastic:create-index book -vvv
16:01:53 INFO      [http_client] Request: "HEAD http://elasticsearch:9200/book_2020-07-14-160150"
16:01:53 INFO      [http_client] Response: "404 http://elasticsearch:9200/book_2020-07-14-160150"

In HttpClientTransport.php line 84:
                                          
  [Elastica\Exception\ResponseException]  
                                          

Exception trace:
  at /srv/api/vendor/jolicode/elastically/src/Transport/HttpClientTransport.php:84
 JoliCode\Elastically\Transport\HttpClientTransport->exec() at /srv/api/vendor/ruflin/elastica/src/Request.php:181
 Elastica\Request->send() at /srv/api/vendor/ruflin/elastica/src/Client.php:521
 Elastica\Client->request() at /srv/api/vendor/ruflin/elastica/src/Client.php:556
 Elastica\Client->requestEndpoint() at /srv/api/vendor/ruflin/elastica/src/Index.php:638
 Elastica\Index->requestEndpoint() at /srv/api/vendor/ruflin/elastica/src/Index.php:420
 Elastica\Index->exists() at /srv/api/vendor/jolicode/elastically/src/IndexBuilder.php:42
 JoliCode\Elastically\IndexBuilder->createIndex() at /srv/api/src/Command/ElasticCreateIndexCommand.php:40
 App\Command\ElasticCreateIndexCommand->execute() at /srv/api/vendor/symfony/console/Command/Command.php:258
 Symfony\Component\Console\Command\Command->run() at /srv/api/vendor/symfony/console/Application.php:929
 Symfony\Component\Console\Application->doRunCommand() at /srv/api/vendor/symfony/framework-bundle/Console/Application.php:96
 Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at /srv/api/vendor/symfony/console/Application.php:264
 Symfony\Component\Console\Application->doRun() at /srv/api/vendor/symfony/framework-bundle/Console/Application.php:82
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /srv/api/vendor/symfony/console/Application.php:140
 Symfony\Component\Console\Application->run() at /srv/api/bin/console:43

My services.yaml

services:
    # ...
    JoliCode\Elastically\Transport\HttpClientTransport: ~
    JoliCode\Elastically\Client:
        arguments:
            $config:
                host: '%env(ELASTICSEARCH_HOST)%'
                port: '%env(ELASTICSEARCH_PORT)%'
                transport: '@JoliCode\Elastically\Transport\HttpClientTransport'
                elastically_mappings_directory: '%kernel.project_dir%/config/elasticsearch/mappings'
                elastically_serializer: '@serializer'
                elastically_bulk_size: 100
                elastically_index_class_mapping:
                    book: App\Projections\Book
            $logger: '@logger'

If I comment transport key, everything works fine

Thanks @jon-ht, thanks a lot for reporting this issue with the Symfony transport. I just pushed a fix, could you test it? (you can download the file here: https://github.com/jolicode/elastically/blob/8e9ec5c4a88f0da93adbbae61c96bbe710a6f94f/src/Transport/HttpClientTransport.php

Hi,

Thanks for your fix @damienalexandre. I can confirm it solves the exception and I can use HTTP Client now :)

The fix is released, thank for your help making this library better!