创建客户端
public static RestHighLevelClient getClient() {
String elasticsearchHosts = "10.1.24.223:9200,10.1.24.224:9200,10.1.24.225:9200";
String[] hosts = elasticsearchHosts.split(",");
HttpHost[] httpHosts = new HttpHost[hosts.length];
for (int i = 0; i < hosts.length; i++) {
String[] hostAndPort = hosts[i].split(":");
String host = hostAndPort[0];
int port = Integer.parseInt(hostAndPort[1]);
httpHosts[i] = new HttpHost(host, port, "http");
}
RestHighLevelClient client = new RestHighLevelClient(
RestClient.builder(httpHosts));
return client;
}
查询
需求
实现如下查询:
GET /disease/_search
{
"_source": {
"includes": [ "disease_*", "info" ],
"excludes": [ "" ]
},
"query": {
"bool": {
"filter": [
{
"range": {
"high_age":