1

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

2 Answers 2

0

ElasticSearch must 5.X Then the problem will slove

Sign up to request clarification or add additional context in comments.

Comments

0

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.