Tag Archives: ES error

[Solved] ES Error: Elasticsearch health check failed

Original error report:

2020-11-30 18:39:08.019  WARN 17664 --- [-192.168.113.22] s.b.a.e.ElasticsearchRestHealthIndicator : Elasticsearch health check failed

java.net.ConnectException: Timeout connecting to [localhost/127.0.0.1:9200]
	at org.elasticsearch.client.RestClient$SyncResponseListener.get(RestClient.java:943) ~[elasticsearch-rest-client-6.4.3.jar:6.4.3]
	at org.elasticsearch.client.RestClient.performRequest(RestClient.java:227) ~[elasticsearch-rest-client-6.4.3.jar:6.4.3]
	at org.springframework.boot.actuate.elasticsearch.ElasticsearchRestHealthIndicator.doHealthCheck(ElasticsearchRestHealthIndicator.java:60) ~[spring-boot-actuator-2.1.7.RELEASE.jar:2.1.7.RELEASE]
	at org.springframework.boot.actuate.health.AbstractHealthIndicator.health(AbstractHealthIndicator.java:82) ~[spring-boot-actuator-2.1.7.RELEASE.jar:2.1.7.RELEASE]
	at org.springframework.boot.actuate.health.CompositeHealthIndicator.health(CompositeHealthIndicator.java:95) [spring-boot-actuator-2.1.7.RELEASE.jar:2.1.7.RELEASE]
	at org.springframework.boot.actuate.health.HealthEndpoint.health(HealthEndpoint.java:50) [spring-boot-actuator-2.1.7.RELEASE.jar:2.1.7.RELEASE]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_161]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_161]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_161]
	at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:282) [spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.boot.actuate.endpoint.invoke.reflect.ReflectiveOperationInvoker.invoke(ReflectiveOperationInvoker.java:76) [spring-boot-actuator-2.1.7.RELEASE.jar:2.1.7.RELEASE]
	at org.springframework.boot.actuate.endpoint.annotation.AbstractDiscoveredOperation.invoke(AbstractDiscoveredOperation.java:60) [spring-boot-actuator-2.1.7.RELEASE.jar:2.1.7.RELEASE]
	at org.springframework.boot.actuate.endpoint.jmx.EndpointMBean.invoke(EndpointMBean.java:121) [spring-boot-actuator-2.1.7.RELEASE.jar:2.1.7.RELEASE]
	at org.springframework.boot.actuate.endpoint.jmx.EndpointMBean.invoke(EndpointMBean.java:96) [spring-boot-actuator-2.1.7.RELEASE.jar:2.1.7.RELEASE]
	at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) [na:1.8.0_161]
	at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) [na:1.8.0_161]
	at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468) [na:1.8.0_161]
	at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76) [na:1.8.0_161]
	at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309) [na:1.8.0_161]
	at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1401) [na:1.8.0_161]
	at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829) [na:1.8.0_161]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_161]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_161]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_161]
	at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:361) [na:1.8.0_161]
	at sun.rmi.transport.Transport$1.run(Transport.java:200) [na:1.8.0_161]
	at sun.rmi.transport.Transport$1.run(Transport.java:197) [na:1.8.0_161]
	at java.security.AccessController.doPrivileged(Native Method) [na:1.8.0_161]
	at sun.rmi.transport.Transport.serviceCall(Transport.java:196) [na:1.8.0_161]
	at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568) [na:1.8.0_161]
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826) [na:1.8.0_161]
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683) [na:1.8.0_161]
	at java.security.AccessController.doPrivileged(Native Method) [na:1.8.0_161]
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682) [na:1.8.0_161]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[na:1.8.0_161]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[na:1.8.0_161]
	at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_161]
Caused by: java.net.ConnectException: Timeout connecting to [localhost/127.0.0.1:9200]
	at org.apache.http.nio.pool.RouteSpecificPool.timeout(RouteSpecificPool.java:169) ~[httpcore-nio-4.4.11.jar:4.4.11]
	at org.apache.http.nio.pool.AbstractNIOConnPool.requestTimeout(AbstractNIOConnPool.java:628) ~[httpcore-nio-4.4.11.jar:4.4.11]
	at org.apache.http.nio.pool.AbstractNIOConnPool$InternalSessionRequestCallback.timeout(AbstractNIOConnPool.java:894) ~[httpcore-nio-4.4.11.jar:4.4.11]
	at org.apache.http.impl.nio.reactor.SessionRequestImpl.timeout(SessionRequestImpl.java:183) ~[httpcore-nio-4.4.11.jar:4.4.11]
	at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processTimeouts(DefaultConnectingIOReactor.java:210) ~[httpcore-nio-4.4.11.jar:4.4.11]
	at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processEvents(DefaultConnectingIOReactor.java:155) ~[httpcore-nio-4.4.11.jar:4.4.11]
	at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor.execute(AbstractMultiworkerIOReactor.java:351) ~[httpcore-nio-4.4.11.jar:4.4.11]
	at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.execute(PoolingNHttpClientConnectionManager.java:221) ~[httpasyncclient-4.1.4.jar:4.1.4]
	at org.apache.http.impl.nio.client.CloseableHttpAsyncClientBase$1.run(CloseableHttpAsyncClientBase.java:64) ~[httpasyncclient-4.1.4.jar:4.1.4]
	... 1 common frames omitted

Solution: add the following configuration to solve the problem successfully

  data:
    elasticsearch:
      repositories:
        enabled: true
      cluster-nodes: 192.168.136.137:9300
      cluster-name: docker-cluster
  #      Add the following configuration to pass the health check
  elasticsearch:
    rest:
      uris: ["http://192.168.136.137:9200"]

ES Error: Elasticsearch health check failed [How to Solve]

Original error report:

2020-11-30 18:39:08.019  WARN 17664 --- [-192.168.113.22] s.b.a.e.ElasticsearchRestHealthIndicator : Elasticsearch health check failed

java.net.ConnectException: Timeout connecting to [localhost/127.0.0.1:9200]
	at org.elasticsearch.client.RestClient$SyncResponseListener.get(RestClient.java:943) ~[elasticsearch-rest-client-6.4.3.jar:6.4.3]
	at org.elasticsearch.client.RestClient.performRequest(RestClient.java:227) ~[elasticsearch-rest-client-6.4.3.jar:6.4.3]
	at org.springframework.boot.actuate.elasticsearch.ElasticsearchRestHealthIndicator.doHealthCheck(ElasticsearchRestHealthIndicator.java:60) ~[spring-boot-actuator-2.1.7.RELEASE.jar:2.1.7.RELEASE]
	at org.springframework.boot.actuate.health.AbstractHealthIndicator.health(AbstractHealthIndicator.java:82) ~[spring-boot-actuator-2.1.7.RELEASE.jar:2.1.7.RELEASE]
	at org.springframework.boot.actuate.health.CompositeHealthIndicator.health(CompositeHealthIndicator.java:95) [spring-boot-actuator-2.1.7.RELEASE.jar:2.1.7.RELEASE]
	at org.springframework.boot.actuate.health.HealthEndpoint.health(HealthEndpoint.java:50) [spring-boot-actuator-2.1.7.RELEASE.jar:2.1.7.RELEASE]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_161]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_161]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_161]
	at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:282) [spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.boot.actuate.endpoint.invoke.reflect.ReflectiveOperationInvoker.invoke(ReflectiveOperationInvoker.java:76) [spring-boot-actuator-2.1.7.RELEASE.jar:2.1.7.RELEASE]
	at org.springframework.boot.actuate.endpoint.annotation.AbstractDiscoveredOperation.invoke(AbstractDiscoveredOperation.java:60) [spring-boot-actuator-2.1.7.RELEASE.jar:2.1.7.RELEASE]
	at org.springframework.boot.actuate.endpoint.jmx.EndpointMBean.invoke(EndpointMBean.java:121) [spring-boot-actuator-2.1.7.RELEASE.jar:2.1.7.RELEASE]
	at org.springframework.boot.actuate.endpoint.jmx.EndpointMBean.invoke(EndpointMBean.java:96) [spring-boot-actuator-2.1.7.RELEASE.jar:2.1.7.RELEASE]
	at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) [na:1.8.0_161]
	at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) [na:1.8.0_161]
	at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468) [na:1.8.0_161]
	at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76) [na:1.8.0_161]
	at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309) [na:1.8.0_161]
	at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1401) [na:1.8.0_161]
	at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829) [na:1.8.0_161]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_161]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_161]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_161]
	at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:361) [na:1.8.0_161]
	at sun.rmi.transport.Transport$1.run(Transport.java:200) [na:1.8.0_161]
	at sun.rmi.transport.Transport$1.run(Transport.java:197) [na:1.8.0_161]
	at java.security.AccessController.doPrivileged(Native Method) [na:1.8.0_161]
	at sun.rmi.transport.Transport.serviceCall(Transport.java:196) [na:1.8.0_161]
	at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568) [na:1.8.0_161]
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826) [na:1.8.0_161]
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683) [na:1.8.0_161]
	at java.security.AccessController.doPrivileged(Native Method) [na:1.8.0_161]
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682) [na:1.8.0_161]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[na:1.8.0_161]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[na:1.8.0_161]
	at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_161]
Caused by: java.net.ConnectException: Timeout connecting to [localhost/127.0.0.1:9200]
	at org.apache.http.nio.pool.RouteSpecificPool.timeout(RouteSpecificPool.java:169) ~[httpcore-nio-4.4.11.jar:4.4.11]
	at org.apache.http.nio.pool.AbstractNIOConnPool.requestTimeout(AbstractNIOConnPool.java:628) ~[httpcore-nio-4.4.11.jar:4.4.11]
	at org.apache.http.nio.pool.AbstractNIOConnPool$InternalSessionRequestCallback.timeout(AbstractNIOConnPool.java:894) ~[httpcore-nio-4.4.11.jar:4.4.11]
	at org.apache.http.impl.nio.reactor.SessionRequestImpl.timeout(SessionRequestImpl.java:183) ~[httpcore-nio-4.4.11.jar:4.4.11]
	at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processTimeouts(DefaultConnectingIOReactor.java:210) ~[httpcore-nio-4.4.11.jar:4.4.11]
	at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processEvents(DefaultConnectingIOReactor.java:155) ~[httpcore-nio-4.4.11.jar:4.4.11]
	at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor.execute(AbstractMultiworkerIOReactor.java:351) ~[httpcore-nio-4.4.11.jar:4.4.11]
	at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.execute(PoolingNHttpClientConnectionManager.java:221) ~[httpasyncclient-4.1.4.jar:4.1.4]
	at org.apache.http.impl.nio.client.CloseableHttpAsyncClientBase$1.run(CloseableHttpAsyncClientBase.java:64) ~[httpasyncclient-4.1.4.jar:4.1.4]
	... 1 common frames omitted

Solution: add the following configuration to solve the problem successfully

  data:
    elasticsearch:
      repositories:
        enabled: true
      cluster-nodes: 192.168.136.137:9300
      cluster-name: docker-cluster
  #      Add the following configuration to pass the health check
  elasticsearch:
    rest:
      uris: ["http://192.168.136.137:9200"]

ES Error: Alternatively, set fielddata=true on [How to Solve]

Es reports an error when executing aggregate query: alternately, set fielddata = true on

GET /megacorp/employee/_search
{
  "aggs": {
    "all_interests": {
      "terms": { "field": "interests" }
    }
  }
}

Execute the following command to start fielddata

PUT /your_index_name/_mapping?pretty
{
  "properties": {
    "your_field_name": { 
      "type": "text",
      "fielddata": true
    }
  }
}

How to Solve ES error: “illegal_argument_exception”

The specific errors reported by ES are as follows:

{
“error”: {
“root_cause”: [
{
“type”: “illegal_argument_exception”,
“reason”: “Fielddata is disabled on text fields by default. Set fielddata=true on [createHour] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead.”
}
],
“type”: “search_phase_execution_exception”,
“reason”: “all shards failed”,
“phase”: “query”,
“grouped”: true,
“failed_shards”: [
{
“shard”: 0,
“index”: “gmall1205_order”,
“node”: “LCQa858ERH6qw_7asM2R3Q”,
“reason”: {
“type”: “illegal_argument_exception”,
“reason”: “Fielddata is disabled on text fields by default. Set fielddata=true on [createHour] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead.”
}
}
],
“caused_by”: {
“type”: “illegal_argument_exception”,
“reason”: “Fielddata is disabled on text fields by default. Set fielddata=true on [createHour] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead.”,
“caused_by”: {
“type”: “illegal_argument_exception”,
“reason”: “Fielddata is disabled on text fields by default. Set fielddata=true on [createHour] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead.”
}
}
},
“status”: 400
}

2: The statement that caused this error query:

GET gmall1205_order/_search
{
“query” : {
“bool” : {
“filter” : {
“term” : {
“createDate” : “2019-09-17”
}
}
}
},
“aggregations” : {
“groupby_createHour” : {
“terms” : {
“field” : “createHour”,
“size” : 24
},
“aggregations” : {
“sum_totalamount” : {
“sum” : {
“field” : “totalAmount”
}
}
}
}
}
}

3: java code:

@Override
public Map getOrderAmontHourMap(String date) {

    SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
    BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();
    boolQueryBuilder.filter(new TermQueryBuilder("createDate",date));
    searchSourceBuilder.query(boolQueryBuilder);
    TermsBuilder termsBuilder = AggregationBuilders.terms("groupby_createHour")
            .field("createHour.keyword").size(24);
    SumBuilder sumBuilder = AggregationBuilders.sum("sum_totalamount").field("totalAmount");

    termsBuilder.subAggregation(sumBuilder);
    searchSourceBuilder.aggregation(termsBuilder);


    Search search = new Search.Builder(searchSourceBuilder.toString()).addIndex(GmallConstant.ES_INDEX_ORDER).addType("_doc").build();

    System.out.println(searchSourceBuilder.toString());

    Map<String,Double> hourMap=new HashMap<>();
    try {
        SearchResult searchResult = jestClient.execute(search);
        System.out.println("====>"+searchResult.toString() + searchResult.getTotal());
        List<TermsAggregation.Entry> buckets = searchResult.getAggregations().getTermsAggregation("groupby_createHour").getBuckets();
        for (TermsAggregation.Entry bucket : buckets) {
            Double hourAmount = bucket.getSumAggregation("sum_totalamount").getSum();
            String hourkey = bucket.getKey();
            hourMap.put(hourkey,hourAmount);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    return hourMap;
}

Error analysis:

“Fielddata is disabled on text fields by default. Set fielddata=true on [createHour] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead

The Fielddata text field is disabled by default. Set fielddata = true (createHour) in order to load fielddata uninverting inverting index in memory. Note that this can use a lot of memory. Or use a keyword field

 

4: Solution

The first:

GET gmall1205_order/_search
{
“query” : {
“bool” : {
“filter” : {
“term” : {
“createDate” : “2019-09-17”
}
}
}
},
“aggregations” : {
“groupby_createHour” : {
“terms” : {
“field” : “createHou.keyword”,
“size” : 24
},
“aggregations” : {
“sum_totalamount” : {
“sum” : {
“field” : “totalAmount”
}
}
}
}
}
}

 

 The second: the solution, custom indexing rules, do not use the default value to create the index

PUT gmall1205_order
{
“mappings” : {
“_doc” : {
“properties” : {
“provinceId” : {
“type” : “keyword”
},
“consignee” : {
“type” : “keyword”,
“index”:false
},
“consigneeTel” : {
“type” : “keyword”,
“index”:false
},
“createDate” : {
“type” : “keyword”
},
“createHour” : {
“type” : “keyword”
},
“createHourMinute” : {
“type” : “keyword”
},
“createTime” : {
“type” : “keyword”
},
“deliveryAddress” : {
“type” : “keyword”
},
“expireTime” : {
“type” : “keyword”
},
“id” : {
“type” : “keyword”
},
“imgUrl” : {
“type” : “keyword”,
“index”:false
},
“operateTime” : {
“type” : “keyword”
},
“orderComment” : {
“type” : “keyword”,
“index”:false
},
“orderStatus” : {
“type” : “keyword”
},
“outTradeNo” : {
“type” : “keyword”,
“index”:false
},
“parentOrderId” : {
“type” : “keyword”
},
“paymentWay” : {
“type” : “keyword”
},
“totalAmount” : {
“type” : “double”
},
“trackingNo” : {
“type” : “keyword”
},
“tradeBody” : {
“type” : “keyword”,
“index”:false
},
“userId” : {
“type” : “keyword”
}
}
}
}
}