设置elasticsearch的java heap大小:
The default installation of Elasticsearch is configured with a 1 GB heap.
There are two ways to change the heap size in Elasticsearch.
1、The easiest is to set an environment variable called ES_HEAP_SIZE
.
When the server process starts, it will read this environment variable and set the heap accordingly. As an example, you can set it via the command line as follows:
2、you can pass in the heap size via a command-line argument when starting the process, if that is easier for your setup:
-Xmx(maximun allowed memory for the process)
-Xms(minimun allowed memory for the process)
还有另一种方式,可以直接修改es的启动脚本,修改默认的JAVA_OPTS设置
ES_MIN_MEM=256m #-Xms
fi
if [ "x$ES_MAX_MEM" = "x" ]; then
ES_MAX_MEM=1g # -Xmx
fi
if [ "x$ES_HEAP_SIZE" != "x" ]; then
ES_MIN_MEM=$ES_HEAP_SIZE
ES_MAX_MEM=$ES_HEAP_SIZE
fi
利用java客户端连接远程elasticsearch服务器时,
实例化client对象的方式如下:
Client client = null; try { client = TransportClient.builder().build() .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("master001"), 9300)); } catch(UnknownHostException e){ System.out.println("unkown host: " +e.getMessage()); } finally { return client; }
抛出异常:NoNodeAvailableException[None of the configured nodes are available: []].
解决此异常需要设置cluster.name属性,方式如下:
Client client = null; try { client = TransportClient.builder().settings(Settings.builder().put("cluster.name", "cobub-es-testing")).build() .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("master001"), 9300)); } catch(UnknownHostException e){ System.out.println("unkown host: " +e.getMessage()); } finally { return client; }
修改后,连接正常。
参考:
Government Blog: Java Clients for Elasticsearch;
Spring Data Es in Github: spring-projects/spring-data-elasticsearch;