简体   繁体   中英

Can't connect to elasticsearch on port 9300 in docker

I'm running elasticsearch through docker on my local machine and can access it normally over the REST API on port 9200.

Apache flink uses for communication with elasticsearch over port 9300.

My goal is to put data from apache flink to elasticsearch over an sink, but on every execution of my program I get the java error:

Elasticsearch client is not connected to any Elasticsearch nodes!

My docker command to run the container looks like this:

docker run --rm -d -p 9200:9200 -p 9300:9300 -p 5601:5601 --name es-kibana nshou/elasticsearch-kibana

I also tried to open port 9300 over "-p 0.0.0.0:9300:9300" or to use the official docker container for elasticsearch.

Is anyone also run into this problem and have any solution? Next thing I want to try is install elasticsearch locally on my machine, but I think the docker way is more rewarding.

Here is also my flink code and the creation of the index and mapping in elasticsearch:

List<InetSocketAddress> transports = new ArrayList<>();
    transports.add(new InetSocketAddress(InetAddress.getByName("0.0.0.0"), 9300));

    tweets.addSink(new ElasticsearchSink<Tuple2<String, Integer>>(
            config,
            transports,
            new ESSink()));

curl for indexing ES:

curl --request PUT --url http://localhost:9200/twitter-bd

curl for mapping ES:

curl --request PUT 
--url http://localhost:9200/twitter-bd/_mapping/twitter-wordcount \
--header 'content-type: application/json' \
--data '{
    "twitter-wordcount": {
        "properties": {
            "word": {"type": "string"},
            "cnt": {"type": "integer"}
        }
     }
}'

Create a docker-compose file docker-compose.yml

version: '2'
services:
    elasticsearch:
        container_name: elasticsearch
        image: elasticsearch:2.4.1
        # UNCOMMENT BELOW LINES TO HAVE PERSISTAN STORAGE
        # volumes:
        #     - /var/db/elasticsearch/:/usr/share/elasticsearch/data/
        ports:
            - 9200:9200
            - 9300:9300

RUN

docker-compose up -d

Use 9300 port to communicate to ES

Create Content

curl -XPUT " http://localhost:9200/playground/equipment/1 " -d ' { "type": "slide", "quantity": 2 }'

Read Content

curl -XGET " http://localhost:9200/playground/equipment/1 "

How To Interact with Data in ElasticSearch Using CRUD Operations

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM