Last Updated
Viewed 29 Times

I 'm want to run ElasticSearch on docker and connect rails with it.

this is my docker-compose.yml file

version: '3'
services:
  db:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: P@ssw0rd
      MYSQL_DATABASE: chatsystem
      MYSQL_USER: root
      MYSQL_PASSWORD: P@ssw0rd
    ports:
      - "3307:3306"

  es01:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.4.2
    container_name: es01
    environment:
      - node.name=es01
      - cluster.name=es-docker-cluster
      - discovery.seed_hosts=es02,es03
      - cluster.initial_master_nodes=es01,es02,es03
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - data01:/usr/share/elasticsearch/data
    ports:
      - 9200:9200
    networks:
      - elastic

  es02:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.4.2
    container_name: es02
    environment:
      - node.name=es02
      - cluster.name=es-docker-cluster
      - discovery.seed_hosts=es01,es03
      - cluster.initial_master_nodes=es01,es02,es03
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - data02:/usr/share/elasticsearch/data
    networks:
      - elastic
  es03:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.4.2
    container_name: es03
    environment:
      - node.name=es03
      - cluster.name=es-docker-cluster
      - discovery.seed_hosts=es01,es02
      - cluster.initial_master_nodes=es01,es02,es03
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - data03:/usr/share/elasticsearch/data
    networks:
      - elastic

  app:
    build: .
    command: bundle exec rails s -p 3000 -b '0.0.0.0'
    volumes:
      - ".:/ChatSystem"
    depends_on:
      - db
      - es01
      - es02
      - es03
    ports:
      - "3000:3000"
    links:
      - db
      - es01
      - es02
      - es03
    environment:
      DB_USER: root
      DB_NAME: chatsystem
      DB_PASSWORD: P@ssw0rd
      DB_HOST: db

volumes:
  data01:
    driver: local
  data02:
    driver: local
  data03:
    driver: local

networks:
  elastic:
    driver: bridge

When I run docker-compose up and access localhost:9200 through the browser. I get this response

{
  "name": "es01",
  "cluster_name": "es-docker-cluster",
  "cluster_uuid": "fNDAvsI6QUyHkzy919PHhw",
  "version": {
    "number": "7.4.2",
    "build_flavor": "default",
    "build_type": "docker",
    "build_hash": "2f90bbf7b93631e52bafb59b3b049cb44ec25e96",
    "build_date": "2019-10-28T20:40:44.881551Z",
    "build_snapshot": false,
    "lucene_version": "8.2.0",
    "minimum_wire_compatibility_version": "6.8.0",
    "minimum_index_compatibility_version": "6.0.0-beta1"
  },
  "tagline": "You Know, for Search"
}

When i try create new "message" i get this error

Errno::EADDRNOTAVAIL (Failed to open TCP connection to localhost:9200 (Cannot assign requested address - connect(2) for "localhost" port 9200))

message.rb file

class Message < ApplicationRecord
  include Elasticsearch::Model
  include Elasticsearch::Model::Callbacks

  settings do
    mappings dynamic: false do
      indexes :message, type: :text
    end
  end

end

Message.import force: true

I 'm using this gems

gem 'elasticsearch-model', git: 'git://github.com/elastic/elasticsearch-rails.git', branch: 'master'
gem 'elasticsearch-rails', git: 'git://github.com/elastic/elasticsearch-rails.git', branch: 'master'

I'm trying to run elastic search on docker I build a container for rails app connected with mysql container I want to connect this rails container with the elastic container but I get this error

Failed to open TCP connection to localhost:9200 (Cannot assign requested address - connect(2) for "localhost" port 9200)

when I run docker-compose up these urls work fine http://localhost:3000/

http://localhost:9200/

but I got that error with this url http://localhost:3000/messages

Failed to open TCP connection to localhost:9200 (Cannot assign requested address - connect(2) for "localhost" port 9200)

I want to get a response from this url http://localhost:3000/messages

how can I open port 9200 ??????????????

this my docker-compose.yml file

version: '2'
services:

  db:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: chat_system
      MYSQL_USER: appuser
      MYSQL_PASSWORD: password
    ports:
      - "3307:3306"

elastic:
  image: docker.elastic.co/elasticsearch/elasticsearch:6.4.0
  environment:
    TAKE_FILE_OWNERSHIP: "true"
    network.host: "0.0.0.0"
    http.port: "9200"
    transport.host: localhost
    transport.tcp.port: "9300"
    xpack.ml.enabled: "false"
# volumes:
#   - ./.data/elastic:/usr/share/elasticsearch/data
  ports:
    - "9200:9200"
    - "9300:9300"
  ulimits:
    nofile:
      soft: "65536"
      hard: "65536"

 app:
   build: .
   command: bundle exec rails s -p 3000 -b '0.0.0.0'
   volumes:
     - ".:/chat_system"
   ports:
     - "3000:3000"
   depends_on:
    - db
    - elastic
   links:
    - db
    - elastic
   environment:
     DB_USER: root
     DB_NAME: chat_system
     DB_PASSWORD: password
     DB_HOST: db
     ELASTIC_HOST: "localhost"
     ELASTIC_PORT: "9200"

I run this command to get elastic logs

     sudo docker-compose logs elastic

and I get this

Attaching to docker_chat_elastic_1
elastic_1  | OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
elastic_1  | [2019-09-24T17:58:29,261][INFO ][o.e.n.Node               ] [] initializing ...
elastic_1  | [2019-09-24T17:58:29,722][INFO ][o.e.e.NodeEnvironment    ] [WwjX-hI] using [1] data paths, mounts [[/ (overlay)]], net usable_space [735.2gb], net total_space [895.5gb], types [overlay]
elastic_1  | [2019-09-24T17:58:29,723][INFO ][o.e.e.NodeEnvironment    ] [WwjX-hI] heap size [989.8mb], compressed ordinary object pointers [true]
elastic_1  | [2019-09-24T17:58:29,729][INFO ][o.e.n.Node               ] [WwjX-hI] node name derived from node ID [WwjX-hIPSZ-7L9XS1bYQFA]; set [node.name] to override
elastic_1  | [2019-09-24T17:58:29,730][INFO ][o.e.n.Node               ] [WwjX-hI] version[6.4.0], pid[1], build[default/tar/595516e/2018-08-17T23:18:47.308994Z], OS[Linux/4.4.0-142-generic/amd64], JVM["Oracle Corporation"/OpenJDK 64-Bit Server VM/10.0.2/10.0.2+13]
elastic_1  | [2019-09-24T17:58:29,731][INFO ][o.e.n.Node               ] [WwjX-hI] JVM arguments [-Xms1g, -Xmx1g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -XX:-OmitStackTraceInFastThrow, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Djava.io.tmpdir=/tmp/elasticsearch.arEsgr84, -XX:+HeapDumpOnOutOfMemoryError, -XX:HeapDumpPath=data, -XX:ErrorFile=logs/hs_err_pid%p.log, -Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m, -Djava.locale.providers=COMPAT, -XX:UseAVX=2, -Des.cgroups.hierarchy.override=/, -Des.path.home=/usr/share/elasticsearch, -Des.path.conf=/usr/share/elasticsearch/config, -Des.distribution.flavor=default, -Des.distribution.type=tar]
elastic_1  | [2019-09-24T17:58:31,488][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [aggs-matrix-stats]
elastic_1  | [2019-09-24T17:58:31,489][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [analysis-common]
elastic_1  | [2019-09-24T17:58:31,489][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [ingest-common]
elastic_1  | [2019-09-24T17:58:31,489][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [lang-expression]
elastic_1  | [2019-09-24T17:58:31,489][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [lang-mustache]
elastic_1  | [2019-09-24T17:58:31,489][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [lang-painless]
elastic_1  | [2019-09-24T17:58:31,489][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [mapper-extras]
elastic_1  | [2019-09-24T17:58:31,489][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [parent-join]
elastic_1  | [2019-09-24T17:58:31,489][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [percolator]
elastic_1  | [2019-09-24T17:58:31,490][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [rank-eval]
elastic_1  | [2019-09-24T17:58:31,490][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [reindex]
elastic_1  | [2019-09-24T17:58:31,490][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [repository-url]
elastic_1  | [2019-09-24T17:58:31,490][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [transport-netty4]
elastic_1  | [2019-09-24T17:58:31,490][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [tribe]
elastic_1  | [2019-09-24T17:58:31,490][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [x-pack-core]
elastic_1  | [2019-09-24T17:58:31,490][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [x-pack-deprecation]
elastic_1  | [2019-09-24T17:58:31,490][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [x-pack-graph]
elastic_1  | [2019-09-24T17:58:31,490][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [x-pack-logstash]
elastic_1  | [2019-09-24T17:58:31,490][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [x-pack-ml]
elastic_1  | [2019-09-24T17:58:31,490][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [x-pack-monitoring]
elastic_1  | [2019-09-24T17:58:31,491][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [x-pack-rollup]
elastic_1  | [2019-09-24T17:58:31,491][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [x-pack-security]
elastic_1  | [2019-09-24T17:58:31,491][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [x-pack-sql]
elastic_1  | [2019-09-24T17:58:31,491][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [x-pack-upgrade]
elastic_1  | [2019-09-24T17:58:31,491][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [x-pack-watcher]
elastic_1  | [2019-09-24T17:58:31,492][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded plugin [ingest-geoip]
elastic_1  | [2019-09-24T17:58:31,492][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded plugin [ingest-user-agent]
elastic_1  | [2019-09-24T17:58:33,514][WARN ][o.e.d.s.ScriptModule     ] Script: returning default values for missing document values is deprecated. Set system property '-Des.scripting.exception_for_missing_value=true' to make behaviour compatible with future major versions.
elastic_1  | [2019-09-24T17:58:35,286][INFO ][o.e.x.s.a.s.FileRolesStore] [WwjX-hI] parsed [0] roles from file [/usr/share/elasticsearch/config/roles.yml]
elastic_1  | [2019-09-24T17:58:36,476][INFO ][o.e.d.DiscoveryModule    ] [WwjX-hI] using discovery type [zen]
elastic_1  | [2019-09-24T17:58:37,104][INFO ][o.e.n.Node               ] [WwjX-hI] initialized
elastic_1  | [2019-09-24T17:58:37,105][INFO ][o.e.n.Node               ] [WwjX-hI] starting ...
elastic_1  | [2019-09-24T17:58:37,256][INFO ][o.e.t.TransportService   ] [WwjX-hI] publish_address {127.0.0.1:9300}, bound_addresses {127.0.0.1:9300}
elastic_1  | [2019-09-24T17:58:40,338][INFO ][o.e.c.s.MasterService    ] [WwjX-hI] zen-disco-elected-as-master ([0] nodes joined)[, ], reason: new_master {WwjX-hI}{WwjX-hIPSZ-7L9XS1bYQFA}{iaR_00fyTMuqfMiCpiq1UQ}{localhost}{127.0.0.1:9300}{xpack.installed=true}
elastic_1  | [2019-09-24T17:58:40,343][INFO ][o.e.c.s.ClusterApplierService] [WwjX-hI] new_master {WwjX-hI}{WwjX-hIPSZ-7L9XS1bYQFA}{iaR_00fyTMuqfMiCpiq1UQ}{localhost}{127.0.0.1:9300}{xpack.installed=true}, reason: apply cluster state (from master [master {WwjX-hI}{WwjX-hIPSZ-7L9XS1bYQFA}{iaR_00fyTMuqfMiCpiq1UQ}{localhost}{127.0.0.1:9300}{xpack.installed=true} committed version [1] source [zen-disco-elected-as-master ([0] nodes joined)[, ]]])
elastic_1  | [2019-09-24T17:58:40,359][INFO ][o.e.x.s.t.n.SecurityNetty4HttpServerTransport] [WwjX-hI] publish_address {172.18.0.2:9200}, bound_addresses {0.0.0.0:9200}
elastic_1  | [2019-09-24T17:58:40,359][INFO ][o.e.n.Node               ] [WwjX-hI] started
elastic_1  | [2019-09-24T17:58:40,672][WARN ][o.e.x.s.a.s.m.NativeRoleMappingStore] [WwjX-hI] Failed to clear cache for realms [[]]
elastic_1  | [2019-09-24T17:58:40,751][INFO ][o.e.g.GatewayService     ] [WwjX-hI] recovered [0] indices into cluster_state
elastic_1  | [2019-09-24T17:58:42,283][INFO ][o.e.c.m.MetaDataIndexTemplateService] [WwjX-hI] adding template [.watch-history-9] for index patterns [.watcher-history-9*]
elastic_1  | [2019-09-24T17:58:42,437][INFO ][o.e.c.m.MetaDataIndexTemplateService] [WwjX-hI] adding template [.watches] for index patterns [.watches*]
elastic_1  | [2019-09-24T17:58:42,665][INFO ][o.e.c.m.MetaDataIndexTemplateService] [WwjX-hI] adding template [.triggered_watches] for index patterns [.triggered_watches*]
elastic_1  | [2019-09-24T17:58:42,859][INFO ][o.e.c.m.MetaDataIndexTemplateService] [WwjX-hI] adding template [.monitoring-logstash] for index patterns [.monitoring-logstash-6-*]
elastic_1  | [2019-09-24T17:58:43,045][INFO ][o.e.c.m.MetaDataIndexTemplateService] [WwjX-hI] adding template [.monitoring-es] for index patterns [.monitoring-es-6-*]
elastic_1  | [2019-09-24T17:58:43,305][INFO ][o.e.c.m.MetaDataIndexTemplateService] [WwjX-hI] adding template [.monitoring-alerts] for index patterns [.monitoring-alerts-6]
elastic_1  | [2019-09-24T17:58:44,163][INFO ][o.e.c.m.MetaDataIndexTemplateService] [WwjX-hI] adding template [.monitoring-beats] for index patterns [.monitoring-beats-6-*]
elastic_1  | [2019-09-24T17:58:44,422][INFO ][o.e.c.m.MetaDataIndexTemplateService] [WwjX-hI] adding template [.monitoring-kibana] for index patterns [.monitoring-kibana-6-*]
elastic_1  | [2019-09-24T17:58:45,050][INFO ][o.e.l.LicenseService     ] [WwjX-hI] license [9f6ac6c0-620a-4b71-b3e7-da5bb37b8337] mode [basic] - valid
elastic_1  | [2019-09-24T18:00:15,514][INFO ][o.e.n.Node               ] [WwjX-hI] stopping ...
elastic_1  | [2019-09-24T18:00:15,525][INFO ][o.e.x.w.WatcherService   ] [WwjX-hI] stopping watch service, reason [shutdown initiated]
elastic_1  | [2019-09-24T18:00:15,764][INFO ][o.e.n.Node               ] [WwjX-hI] stopped
elastic_1  | [2019-09-24T18:00:15,764][INFO ][o.e.n.Node               ] [WwjX-hI] closing ...
elastic_1  | [2019-09-24T18:00:15,770][INFO ][o.e.n.Node               ] [WwjX-hI] closed
elastic_1  | OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
elastic_1  | [2019-09-24T18:00:28,430][INFO ][o.e.n.Node               ] [] initializing ...
elastic_1  | [2019-09-24T18:00:28,776][INFO ][o.e.e.NodeEnvironment    ] [WwjX-hI] using [1] data paths, mounts [[/ (overlay)]], net usable_space [735.1gb], net total_space [895.5gb], types [overlay]
elastic_1  | [2019-09-24T18:00:28,777][INFO ][o.e.e.NodeEnvironment    ] [WwjX-hI] heap size [989.8mb], compressed ordinary object pointers [true]
elastic_1  | [2019-09-24T18:00:28,782][INFO ][o.e.n.Node               ] [WwjX-hI] node name derived from node ID [WwjX-hIPSZ-7L9XS1bYQFA]; set [node.name] to override
elastic_1  | [2019-09-24T18:00:28,783][INFO ][o.e.n.Node               ] [WwjX-hI] version[6.4.0], pid[1], build[default/tar/595516e/2018-08-17T23:18:47.308994Z], OS[Linux/4.4.0-142-generic/amd64], JVM["Oracle Corporation"/OpenJDK 64-Bit Server VM/10.0.2/10.0.2+13]
elastic_1  | [2019-09-24T18:00:28,783][INFO ][o.e.n.Node               ] [WwjX-hI] JVM arguments [-Xms1g, -Xmx1g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -XX:-OmitStackTraceInFastThrow, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Djava.io.tmpdir=/tmp/elasticsearch.wSQUCcFj, -XX:+HeapDumpOnOutOfMemoryError, -XX:HeapDumpPath=data, -XX:ErrorFile=logs/hs_err_pid%p.log, -Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m, -Djava.locale.providers=COMPAT, -XX:UseAVX=2, -Des.cgroups.hierarchy.override=/, -Des.path.home=/usr/share/elasticsearch, -Des.path.conf=/usr/share/elasticsearch/config, -Des.distribution.flavor=default, -Des.distribution.type=tar]
elastic_1  | [2019-09-24T18:00:30,057][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [aggs-matrix-stats]
elastic_1  | [2019-09-24T18:00:30,057][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [analysis-common]
elastic_1  | [2019-09-24T18:00:30,058][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [ingest-common]
elastic_1  | [2019-09-24T18:00:30,058][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [lang-expression]
elastic_1  | [2019-09-24T18:00:30,058][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [lang-mustache]
elastic_1  | [2019-09-24T18:00:30,058][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [lang-painless]
elastic_1  | [2019-09-24T18:00:30,058][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [mapper-extras]
elastic_1  | [2019-09-24T18:00:30,058][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [parent-join]
elastic_1  | [2019-09-24T18:00:30,058][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [percolator]
elastic_1  | [2019-09-24T18:00:30,058][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [rank-eval]
elastic_1  | [2019-09-24T18:00:30,058][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [reindex]
elastic_1  | [2019-09-24T18:00:30,058][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [repository-url]
elastic_1  | [2019-09-24T18:00:30,059][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [transport-netty4]
elastic_1  | [2019-09-24T18:00:30,059][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [tribe]
elastic_1  | [2019-09-24T18:00:30,059][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [x-pack-core]
elastic_1  | [2019-09-24T18:00:30,059][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [x-pack-deprecation]
elastic_1  | [2019-09-24T18:00:30,059][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [x-pack-graph]
elastic_1  | [2019-09-24T18:00:30,059][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [x-pack-logstash]
elastic_1  | [2019-09-24T18:00:30,059][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [x-pack-ml]
elastic_1  | [2019-09-24T18:00:30,059][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [x-pack-monitoring]
elastic_1  | [2019-09-24T18:00:30,059][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [x-pack-rollup]
elastic_1  | [2019-09-24T18:00:30,059][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [x-pack-security]
elastic_1  | [2019-09-24T18:00:30,060][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [x-pack-sql]
elastic_1  | [2019-09-24T18:00:30,060][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [x-pack-upgrade]
elastic_1  | [2019-09-24T18:00:30,060][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded module [x-pack-watcher]
elastic_1  | [2019-09-24T18:00:30,060][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded plugin [ingest-geoip]
elastic_1  | [2019-09-24T18:00:30,060][INFO ][o.e.p.PluginsService     ] [WwjX-hI] loaded plugin [ingest-user-agent]
elastic_1  | [2019-09-24T18:00:31,792][WARN ][o.e.d.s.ScriptModule     ] Script: returning default values for missing document values is deprecated. Set system property '-Des.scripting.exception_for_missing_value=true' to make behaviour compatible with future major versions.
elastic_1  | [2019-09-24T18:00:33,335][INFO ][o.e.x.s.a.s.FileRolesStore] [WwjX-hI] parsed [0] roles from file [/usr/share/elasticsearch/config/roles.yml]
elastic_1  | [2019-09-24T18:00:34,159][INFO ][o.e.d.DiscoveryModule    ] [WwjX-hI] using discovery type [zen]
elastic_1  | [2019-09-24T18:00:34,790][INFO ][o.e.n.Node               ] [WwjX-hI] initialized
elastic_1  | [2019-09-24T18:00:34,790][INFO ][o.e.n.Node               ] [WwjX-hI] starting ...
elastic_1  | [2019-09-24T18:00:34,927][INFO ][o.e.t.TransportService   ] [WwjX-hI] publish_address {127.0.0.1:9300}, bound_addresses {127.0.0.1:9300}
elastic_1  | [2019-09-24T18:00:38,001][INFO ][o.e.c.s.MasterService    ] [WwjX-hI] zen-disco-elected-as-master ([0] nodes joined)[, ], reason: new_master {WwjX-hI}{WwjX-hIPSZ-7L9XS1bYQFA}{CzEAmK5jRsOh6lrRagMi_Q}{localhost}{127.0.0.1:9300}{xpack.installed=true}
elastic_1  | [2019-09-24T18:00:38,005][INFO ][o.e.c.s.ClusterApplierService] [WwjX-hI] new_master {WwjX-hI}{WwjX-hIPSZ-7L9XS1bYQFA}{CzEAmK5jRsOh6lrRagMi_Q}{localhost}{127.0.0.1:9300}{xpack.installed=true}, reason: apply cluster state (from master [master {WwjX-hI}{WwjX-hIPSZ-7L9XS1bYQFA}{CzEAmK5jRsOh6lrRagMi_Q}{localhost}{127.0.0.1:9300}{xpack.installed=true} committed version [1] source [zen-disco-elected-as-master ([0] nodes joined)[, ]]])
elastic_1  | [2019-09-24T18:00:38,023][INFO ][o.e.x.s.t.n.SecurityNetty4HttpServerTransport] [WwjX-hI] publish_address {172.18.0.3:9200}, bound_addresses {0.0.0.0:9200}
elastic_1  | [2019-09-24T18:00:38,023][INFO ][o.e.n.Node               ] [WwjX-hI] started
elastic_1  | [2019-09-24T18:00:38,721][WARN ][o.e.x.s.a.s.m.NativeRoleMappingStore] [WwjX-hI] Failed to clear cache for realms [[]]
elastic_1  | [2019-09-24T18:00:38,762][INFO ][o.e.l.LicenseService     ] [WwjX-hI] license [9f6ac6c0-620a-4b71-b3e7-da5bb37b8337] mode [basic] - valid
elastic_1  | [2019-09-24T18:00:38,772][INFO ][o.e.g.GatewayService     ] [WwjX-hI] recovered [0] indices into cluster_state

I am getting the error: Puma caught this error: Failed to open TCP connection to localhost:9200 (Connection refused - connect(2) for "localhost" port 9200) (Faraday::ConnectionFailed) in my rails application in ubuntu 14.04.

below is the output of my elastic search in terminal:

prashanth@prashanth-OptiPlex-390:~$ sudo service elasticsearch restart
 * Starting Elasticsearch Server                                                                                                               prashanth@prashanth-OptiPlex-390:~$ sudo service elasticsearch start
 * Starting Elasticsearch Server                                                                                                                * Already running.                                                                                                                     [ OK ] 
prashanth@prashanth-OptiPlex-390:~$ curl -X GET 'http://localhost:9200'
curl: (7) Failed to connect to localhost port 9200: Connection refused
prashanth@prashanth-OptiPlex-390:~$ 

here are the my elastic search settings in /etc/elasticsearch/elasticsearch.yml file

network.host: 127.0.0.1
transport.tcp.port: 9200
http.port: 9200

error description:

Puma caught this error: Failed to open TCP connection to localhost:9200 (Connection refused - connect(2) for "localhost" port 9200) (Faraday::ConnectionFailed)
/home/prashanth/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/net/http.rb:882:in `rescue in block in connect'
/home/prashanth/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/net/http.rb:879:in `block in connect'
/home/prashanth/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/timeout.rb:91:in `block in timeout'
/home/prashanth/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/timeout.rb:101:in `timeout'
/home/prashanth/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/net/http.rb:878:in `connect'
/home/prashanth/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/net/http.rb:863:in `do_start'
/home/prashanth/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/net/http.rb:852:in `start'
/home/prashanth/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/net/http.rb:1398:in `request'
/home/prashanth/.rvm/gems/ruby-2.3.1/gems/faraday-0.10.1/lib/faraday/adapter/net_http.rb:83:in `perform_request'
/home/prashanth/.rvm/gems/ruby-2.3.1/gems/faraday-0.10.1/lib/faraday/adapter/net_http.rb:41:in `block in call'
/home/prashanth/.rvm/gems/ruby-2.3.1/gems/faraday-0.10.1/lib/faraday/adapter/net_http.rb:88:in `with_net_http_connection'
/home/prashanth/.rvm/gems/ruby-2.3.1/gems/faraday-0.10.1/lib/faraday/adapter/net_http.rb:33:in `call'
/home/prashanth/.rvm/gems/ruby-2.3.1/gems/faraday-0.10.1/lib/faraday/rack_builder.rb:139:in `build_response'
/home/prashanth/.rvm/gems/ruby-2.3.1/gems/faraday-0.10.1/lib/faraday/connection.rb:377:in `run_request'
/home/prashanth/.rvm/gems/ruby-2.3.1/gems/elasticsearch-transport-5.0.0/lib/elasticsearch/transport/transport/http/faraday.rb:23:in `block in perform_request'
/home/prashanth/.rvm/gems/ruby-2.3.1/gems/elasticsearch-transport-5.0.0/lib/elasticsearch/transport/transport/base.rb:257:in `perform_request'
/home/prashanth/.rvm/gems/ruby-2.3.1/gems/elasticsearch-transport-5.0.0/lib/elasticsearch/transport/transport/http/faraday.rb:20:in `perform_request'
/home/prashanth/.rvm/gems/ruby-2.3.1/gems/elasticsearch-transport-5.0.0/lib/elasticsearch/transport/client.rb:128:in `perform_request'

I am using DigitalOcean for my Ruby on Rails app with Elasticsearch. So I am getting

Faraday::ConnectionFailed in PetsController#create
Connection refused - connect(2) for "localhost" port 9200

I am wondering if it is because I am not using localhost on DigitalOcean. I am guessing if I have to change it in my app to start listening to the ip address I am using for DigitalOcean, but am not sure where I should look at.

Similar Question 7 (2 solutions) : Rails Bundle Install failed with Docker

Similar Question 8 (1 solutions) : Docker failed to build on Rails bundle Install rake

cc