Search code examples
ruby-on-railsrubyruby-on-rails-3elasticsearchruby-on-rails-4

uninitialized constant Faraday::Error::ConnectionFailed in elastic-search


I'm implementing elastic-search in rails by following this tutorial

https://iridakos.com/programming/2017/12/03/elasticsearch-and-rails-tutorial

And add these lines to my User.rb include Elasticsearch::Model include Elasticsearch::Model::Callbacks & also installed these two gems gem 'elasticsearch-model' gem 'elasticsearch-rails' but when I try to execute this command Post.import(force: true) it gives me an error

uninitialized constant Faraday::Error::ConnectionFailed


Solution

  • Yes At the end I reached the solution in my case As my project is a dockerized project & I was running elastic search locally that's why my app was not connected with elasticsearch.

    When I Pull a docker image and run elasticsearch from it after adding all credentials in my docker-compose.yml I successfully implement it.

    Note: your kibana and elasticsearch version should be same.

    My docker-compose.yml

    services: 
    
    ## My all services
    elasticsearch:
          image: docker.elastic.co/elasticsearch/elasticsearch:6.8.13
          environment:
            - cluster.name=docker-cluster
            - bootstrap.memory_lock=true
            - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
            - xpack.security.enabled=false
            - xpack.monitoring.enabled=false
            - xpack.graph.enabled=false
            - xpack.watcher.enabled=false
            - discovery.type=single-node
          ulimits:
            memlock:
              soft: -1
              hard: -1
          networks:
            - eb-back_network
          volumes:
            - ./docker_data/elasticsearch/data:/usr/share/elasticsearch/data
          ports:
            - "9200:9200"
            - "9300:9300"
    
    kibana:
        image: docker.elastic.co/kibana/kibana:6.8.13
        restart: always
        volumes:
          - ./kibana.yml:/usr/share/kibana/config/kibana.yml
        environment:
          - ELASTICSEARCH_HOSTS=http://elasticsearch:9200
        ports:
          - "5601:5601"
        networks:
          - eb-back_network
        depends_on:
          - elasticsearch