Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Ask Question
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
I have the same problem
The problem is the incompatibility of Elasticsearch library 5 and 6 and above.
Problems like 'auto_generate_synonyms_phrase_query' and '_key' and '_doc'.
Elasticsearch version 7 library does not support Elasticsearch version 5.
You must version org.elasticsearch :
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>7.*.*</version>
</dependency>
Change to versions 5:
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>5.*.*</version>
</dependency>
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.