问题
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