2
votes

I try to reindex from a remote server. Elasticsearch instance on the remote server is behind a nginx proxy and its url is api.example.com/api/elasticsearch on port 80.

I'm able to access the remote elasticsearch and perform queries. E.g.

curl http://api.example.com:80/api/elasticsearch/_cat/indices?v

gives the expected result.

However when I try to reindex a local elasticsearch index from the remote index as follows

curl -X POST http://elasticsearch:9200/_reindex -d '{ 
    "source": {
        "remote": { 
            "host": "http://api.example.com/api/elasticsearch:80"
        }, 
        "index": "alias_name" 
    }, 
    "dest": { 
        "index": "index_name" 
    }
}'

I receive an error:

{"error":{"root_cause":[{"type":"unknown_host_exception","reason":"api.example.com/api/elasticsearch: Name or service not known"}],"type":"unknown_host_exception","reason":"api.example.com/api/elasticsearch: Name or service not known"},"status":500}
1
In the first example the address string is "api.example.com:80/api/elasticsearch", in the second one is "api.example.com/api/elasticsearch:80". Why you have changed the position of the port in the address string?Lupanoide
When I use api.example.com:80/api/elasticsearch as host in the reindex query I receive this error: [host] must be of the form [scheme]://[host]:[port] but was [api.example.com:80/api/elasticsearch]Khmtrav
I had this exact same issue. My workaround was to introduce another nginx proxy between them that listened on an explicit port and forwarded calls. Pretty silly that this was necessary but it worked great.Bruce MacKenzie

1 Answers

1
votes

According documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html:

The host parameter must contain a scheme, host, port (e.g. https://otherhost:9200) and optional path (e.g. https://otherhost:9200/proxy). The username and password parameters are optional, and when they are present _reindex will connect to the remote Elasticsearch node using basic auth. Be sure to use https when using basic auth or the password will be sent in plain text.

In your case: "http://api.example.com:80/api/elasticsearch" or "http://api.example.com/api/elasticsearch"

Also, most important:

Remote hosts have to be explicitly whitelisted in elasticsearch.yaml using the reindex.remote.whitelist property. It can be set to a comma delimited list of allowed remote host and port combinations (e.g. otherhost:9200, another:9200, 127.0.10.:9200, localhost:)