ElasticSearch Error: Invalid term-aggregator order path [_key]. Unknown aggregation [_key] while performing aggregation from Java

纵饮孤独 提交于 2020-01-16 19:37:06

问题


i'm getting the below error when performing aggregation Error: Invalid term-aggregator order path [_key]. Unknown aggregation [_key] while performing aggregation from Java

code:

 public static void main(String[] args){

 JestClient jestClient = getJestClient();

 SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
 searchSourceBuilder.size(100);
 searchSourceBuilder.aggregation(AggregationBuilders.terms("products").field("myField.keyword").
 valueType(ValueType.STRING).size(100));

 SearchRequest searchRequest = new SearchRequest(); 
 searchRequest.source(searchSourceBuilder);
 Search searchQuery = new Search.Builder(searchSourceBuilder.toString()).
setParameter(Parameters.SCROLL,"5m").setSearchType(SearchType.DFS_QUERY_THEN_FETCH).build();
JestResult hits = jestClient.execute(searchQuery);
System.out.println(hits.getJsonObject);
}

public static void getJestClient(){
JestClientFactory factory = new JestClientFactory();
        factory.setHttpClientConfig(
                new HttpClientConfig.Builder(hostname)
                        .multiThreaded(true)
                        .readTimeout(30000)
                        .build());
        return factory.getObject()
}

Error:

{"error":{"root_cause":[{"type":"aggregation_execution_exception","reason":"Invalid term- 
aggregator order path [_key]. Unknown aggregation [ . 
  _key]"}],"type":"search_phase_execution_exception","reason":"all shards 
 failed","phase":"dfs_query","grouped":true,"failed_shards": 
[{"shard":0,"index":".kibana","node":"RwVYV0S-SVmiqfMuihkcHA","reason": 
{"type":"aggregation_execution_exception","reason":"Invalid term-aggregator order path 
 [_key]. Unknown aggregation [_key]"}}]},"status":500}

when I run from curl i'm getting the output sucessfully.

Curl:

curl -v -X GET "https://hostname/_search?pretty" -H 'Content-Type: application/json' -d 
'{"aggs" : { "products" : { 
   "terms" : {"field" : "myField.keyword","size" : 5}
}}}'

Not sure what is the mistake whether it is the issue with the ElasticSearch java package or i'm doing some mistake.

I'm using Jest-5.x and elasticsearch 7.4.2

Please suggest other alternatives

来源:https://stackoverflow.com/questions/59570496/elasticsearch-error-invalid-term-aggregator-order-path-key-unknown-aggregat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!