欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

已解决:Elasticsearch报错:Invalid interval specified, must be non-null and non-empty

程序员文章站 2022-07-12 14:28:26
...

报错信息:

Exception in thread "main" ElasticsearchStatusException[Elasticsearch exception [type=search_phase_execution_exception, reason=all shards failed]]; nested: ElasticsearchException[Elasticsearch exception [type=illegal_argument_exception, reason=Invalid interval specified, must be non-null and non-empty]]; nested: ElasticsearchException[Elasticsearch exception [type=illegal_argument_exception, reason=Invalid interval specified, must be non-null and non-empty]];
	at org.elasticsearch.rest.BytesRestResponse.errorFromXContent(BytesRestResponse.java:177)
	at org.elasticsearch.client.RestHighLevelClient.parseEntity(RestHighLevelClient.java:1727)
	at org.elasticsearch.client.RestHighLevelClient.parseResponseException(RestHighLevelClient.java:1704)
	at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1467)
	at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1424)
	at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:1394)
	at org.elasticsearch.client.RestHighLevelClient.search(RestHighLevelClient.java:930)
	at com.softsec.util.demoTime.main(demoTime.java:88)
	Suppressed: org.elasticsearch.client.ResponseException: method [POST], host [http://192.168.101.92:9200], URI [/news/_search?typed_keys=true&ignore_unavailable=false&expand_wildcards=open&allow_no_indices=true&ignore_throttled=true&search_type=query_then_fetch&batched_reduce_size=512&ccs_minimize_roundtrips=true], status line [HTTP/1.1 400 Bad Request]
{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Invalid interval specified, must be non-null and non-empty"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"news","node":"8GuMfo5aRz2CCgl49bY0aQ","reason":{"type":"illegal_argument_exception","reason":"Invalid interval specified, must be non-null and non-empty"}}],"caused_by":{"type":"illegal_argument_exception","reason":"Invalid interval specified, must be non-null and non-empty","caused_by":{"type":"illegal_argument_exception","reason":"Invalid interval specified, must be non-null and non-empty"}}},"status":400}
		at org.elasticsearch.client.RestClient.convertResponse(RestClient.java:253)
		at org.elasticsearch.client.RestClient.performRequest(RestClient.java:231)
		at org.elasticsearch.client.RestClient.performRequest(RestClient.java:205)
		at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1454)
		... 4 more

报错信息解释:指定的无效时间间隔,必须为非空且非空;意思是指定的“时间间隔”出了问题;

在ES中设定时间间隔属性的是 interval

已解决:Elasticsearch报错:Invalid interval specified, must be non-null and non-empty

来看Demo:

已解决:Elasticsearch报错:Invalid interval specified, must be non-null and non-empty

加上时间间隔interval后:

已解决:Elasticsearch报错:Invalid interval specified, must be non-null and non-empty

 

查询代码:

GET /news/_search
{
   "size" : 0,
   "aggregations": {
      "sales": {
         "date_histogram": {
            "field": "crawlTime",
            "interval": "month", 
            "format": "yyyy-MM-dd"
         }
      }
   }
}

当然,间隔时间可以自定义(如下图),设置为每两天为一个单位;也可以设成N东或N秒为单位;

已解决:Elasticsearch报错:Invalid interval specified, must be non-null and non-empty