How to connect to elasticsearch server using rest client with IP address

294
July 10, 2019, at 03:00 AM

Here is my code; it's working fine

val client =Option (new RestHighLevelClient(RestClient.builder(new HttpHost("localhost", 9200, "http"))))

but I need use the IP address. For that I am doing this

val client =Option (new RestHighLevelClient(RestClient.builder(new HttpHost("192.168.1.8", 9200, "http"))))

It's throwing

java.net.ConnectException: Connection refused
    at java.base/sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
    at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:779)
    at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processEvent(DefaultConnectingIOReactor.java:171)
    at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processEvents(DefaultConnectingIOReactor.java:145)
    at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor.execute(AbstractMultiworkerIOReactor.java:351)
    at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.execute(PoolingNHttpClientConnectionManager.java:221)
    at org.apache.http.impl.nio.client.CloseableHttpAsyncClientBase$1.run(CloseableHttpAsyncClientBase.java:64)
    at java.base/java.lang.Thread.run(Thread.java:834)

then here in the ES docs https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-network.html under network.host heading it says to do this network.host = 0.0.0.0 in elasticsearch.yml after doing this and starting the elasticsearch server becomes stop with these log

019-07-09T16:03:24,956][INFO ][o.e.e.NodeEnvironment    ] [sara-Inspiron-7773] using [1] data paths, mounts [[/ (/dev/sda7)]], net usable_space [88.4gb], net total_space [141.7gb], types [ext4]
[2019-07-09T16:03:24,966][INFO ][o.e.e.NodeEnvironment    ] [sara-Inspiron-7773] heap size [989.8mb], compressed ordinary object pointers [true]
[2019-07-09T16:03:24,981][INFO ][o.e.n.Node               ] [sara-Inspiron-7773] node name [sara-Inspiron-7773], node ID [RK754dxuRiiCZYeR5NwN-Q], cluster name [elasticsearch]
[2019-07-09T16:03:24,982][INFO ][o.e.n.Node               ] [sara-Inspiron-7773] version[7.1.0], pid[21369], build[default/tar/606a173/2019-05-16T00:43:15.323135Z], OS[Linux/4.15.0-52-generic/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_181/25.181-b13]
[2019-07-09T16:03:24,983][INFO ][o.e.n.Node               ] [sara-Inspiron-7773] JVM home [/usr/lib/jvm/jdk1.8.0_181/jre]
[2019-07-09T16:03:24,983][INFO ][o.e.n.Node               ] [sara-Inspiron-7773] JVM arguments [-Xms1g, -Xmx1g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -Des.networkaddress.cache.ttl=60, -Des.networkaddress.cache.negative.ttl=10, -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-7504410747021569879, -XX:+HeapDumpOnOutOfMemoryError, -XX:HeapDumpPath=data, -XX:ErrorFile=logs/hs_err_pid%p.log, -XX:+PrintGCDetails, -XX:+PrintGCDateStamps, -XX:+PrintTenuringDistribution, -XX:+PrintGCApplicationStoppedTime, -Xloggc:logs/gc.log, -XX:+UseGCLogFileRotation, -XX:NumberOfGCLogFiles=32, -XX:GCLogFileSize=64m, -Dio.netty.allocator.type=unpooled, -Des.path.home=/opt/ifkaar/elasticsearch-7.1.0, -Des.path.conf=/opt/ifkaar/elasticsearch-7.1.0/config, -Des.distribution.flavor=default, -Des.distribution.type=tar, -Des.bundled_jdk=true]
[2019-07-09T16:03:26,370][INFO ][o.e.p.PluginsService     ] [sara-Inspiron-7773] loaded module [aggs-matrix-stats]
[2019-07-09T16:03:26,370][INFO ][o.e.p.PluginsService     ] [sara-Inspiron-7773] loaded module [analysis-common]
[2019-07-09T16:03:26,371][INFO ][o.e.p.PluginsService     ] [sara-Inspiron-7773] loaded module [ingest-common]
[2019-07-09T16:03:26,371][INFO ][o.e.p.PluginsService     ] [sara-Inspiron-7773] loaded module [ingest-geoip]
[2019-07-09T16:03:26,371][INFO ][o.e.p.PluginsService     ] [sara-Inspiron-7773] loaded module [ingest-user-agent]
[2019-07-09T16:03:26,371][INFO ][o.e.p.PluginsService     ] [sara-Inspiron-7773] loaded module [lang-expression]
[2019-07-09T16:03:26,371][INFO ][o.e.p.PluginsService     ] [sara-Inspiron-7773] loaded module [lang-mustache]
[2019-07-09T16:03:26,372][INFO ][o.e.p.PluginsService     ] [sara-Inspiron-7773] loaded module [lang-painless]
[2019-07-09T16:03:26,372][INFO ][o.e.p.PluginsService     ] [sara-Inspiron-7773] loaded module [mapper-extras]
[2019-07-09T16:03:26,372][INFO ][o.e.p.PluginsService     ] [sara-Inspiron-7773] loaded module [parent-join]
[2019-07-09T16:03:26,372][INFO ][o.e.p.PluginsService     ] [sara-Inspiron-7773] loaded module [percolator]
[2019-07-09T16:03:26,373][INFO ][o.e.p.PluginsService     ] [sara-Inspiron-7773] loaded module [rank-eval]
[2019-07-09T16:03:26,373][INFO ][o.e.p.PluginsService     ] [sara-Inspiron-7773] loaded module [reindex]
[2019-07-09T16:03:26,373][INFO ][o.e.p.PluginsService     ] [sara-Inspiron-7773] loaded module [repository-url]
[2019-07-09T16:03:26,373][INFO ][o.e.p.PluginsService     ] [sara-Inspiron-7773] loaded module [transport-netty4]
[2019-07-09T16:03:26,374][INFO ][o.e.p.PluginsService     ] [sara-Inspiron-7773] loaded module [x-pack-ccr]
[2019-07-09T16:03:26,374][INFO ][o.e.p.PluginsService     ] [sara-Inspiron-7773] loaded module [x-pack-core]
[2019-07-09T16:03:26,374][INFO ][o.e.p.PluginsService     ] [sara-Inspiron-7773] loaded module [x-pack-deprecation]
[2019-07-09T16:03:26,374][INFO ][o.e.p.PluginsService     ] [sara-Inspiron-7773] loaded module [x-pack-graph]
[2019-07-09T16:03:26,375][INFO ][o.e.p.PluginsService     ] [sara-Inspiron-7773] loaded module [x-pack-ilm]
[2019-07-09T16:03:26,375][INFO ][o.e.p.PluginsService     ] [sara-Inspiron-7773] loaded module [x-pack-logstash]
[2019-07-09T16:03:26,375][INFO ][o.e.p.PluginsService     ] [sara-Inspiron-7773] loaded module [x-pack-ml]
[2019-07-09T16:03:26,375][INFO ][o.e.p.PluginsService     ] [sara-Inspiron-7773] loaded module [x-pack-monitoring]
[2019-07-09T16:03:26,375][INFO ][o.e.p.PluginsService     ] [sara-Inspiron-7773] loaded module [x-pack-rollup]
[2019-07-09T16:03:26,375][INFO ][o.e.p.PluginsService     ] [sara-Inspiron-7773] loaded module [x-pack-security]
[2019-07-09T16:03:26,376][INFO ][o.e.p.PluginsService     ] [sara-Inspiron-7773] loaded module [x-pack-sql]
[2019-07-09T16:03:26,376][INFO ][o.e.p.PluginsService     ] [sara-Inspiron-7773] loaded module [x-pack-watcher]
[2019-07-09T16:03:26,376][INFO ][o.e.p.PluginsService     ] [sara-Inspiron-7773] no plugins loaded
[2019-07-09T16:03:29,570][INFO ][o.e.x.s.a.s.FileRolesStore] [sara-Inspiron-7773] parsed [0] roles from file [/opt/ifkaar/elasticsearch-7.1.0/config/roles.yml]
[2019-07-09T16:03:30,166][INFO ][o.e.x.m.p.l.CppLogMessageHandler] [sara-Inspiron-7773] [controller/21466] [Main.cc@109] controller (64 bit): Version 7.1.0 (Build a8ee6de8087169) Copyright (c) 2019 Elasticsearch BV
[2019-07-09T16:03:30,537][DEBUG][o.e.a.ActionModule       ] [sara-Inspiron-7773] Using REST wrapper from plugin org.elasticsearch.xpack.security.Security
[2019-07-09T16:03:30,871][INFO ][o.e.d.DiscoveryModule    ] [sara-Inspiron-7773] using discovery type [zen] and seed hosts providers [settings]
[2019-07-09T16:03:31,559][INFO ][o.e.n.Node               ] [sara-Inspiron-7773] initialized
[2019-07-09T16:03:31,559][INFO ][o.e.n.Node               ] [sara-Inspiron-7773] starting ...
[2019-07-09T16:03:31,673][INFO ][o.e.t.TransportService   ] [sara-Inspiron-7773] publish_address {192.168.1.8:9300}, bound_addresses {[::]:9300}
[2019-07-09T16:03:31,679][INFO ][o.e.b.BootstrapChecks    ] [sara-Inspiron-7773] bound or publishing to a non-loopback address, enforcing bootstrap checks
ERROR: [3] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[3]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
[2019-07-09T16:03:31,720][INFO ][o.e.n.Node               ] [sara-Inspiron-7773] stopping ...
[2019-07-09T16:03:31,739][INFO ][o.e.n.Node               ] [sara-Inspiron-7773] stopped
[2019-07-09T16:03:31,740][INFO ][o.e.n.Node               ] [sara-Inspiron-7773] closing ...
[2019-07-09T16:03:31,754][INFO ][o.e.n.Node               ] [sara-Inspiron-7773] closed
[2019-07-09T16:03:31,758][INFO ][o.e.x.m.p.NativeController] [sara-Inspiron-7773] Native controller process has stopped - no new native processes can be started

How can I fix these two issues? Please help.

Answer 1

This thread explains what is happening: https://discuss.elastic.co/t/problems-with-access-to-elasticsearch-form-outside-machine/172450/2

The cluster coordination algorithm has changed in 7.0 234 and in order to be safe it requires some specific configuration. We relax that requirement (that is, we run in a less-safe mode) when you bind to localhost only, but if/when you change network.host we enforce that your configure the cluster safely.

This is covered in the breaking changes documentation 576 for 7.0

https://www.elastic.co/guide/en/elasticsearch/reference/7.0/breaking-changes-7.0.html#breaking_70_discovery_changes

So it looks like you have to make a lot of config changes if you want to run a dev Elasticsearch that binds other than to localhost. It might be easier to bind to localhost and tunnel it out using ssh or similar? GL

Rent Charter Buses Company
READ ALSO
Nested Expressions In JsonPath

Nested Expressions In JsonPath

Could anyone please let me know how to evaluate nested expressions using JsonPath

112
MockBean not injected in MVC Controller test

MockBean not injected in MVC Controller test

I'm trying to test my controller in isolation of the spring application context

288
Use SOCKS5 proxy to access AWS API

Use SOCKS5 proxy to access AWS API

Is it possible to use SOCKS5 proxy for calling AWS API (S3 and SQS)? I found that SKD 111 doesn't support that

158
Is extending the thread faster than implements thread? [on hold]

Is extending the thread faster than implements thread? [on hold]

Yesterday I came across a question from my instructor that whether "implements runnable" method is faster than "extends" thread?

130