I have been trying to get elasticsearch aggregations using Java High-Level Rest Client. It is always returning aggregation name with type information, for example if I have given a "terms" aggregation with name "message", the response contains the returning aggregation name as "sterms#message" which is not expected unless the user specifically asks for type information. In ElasticSearch documentation (Returning the type of the aggregation), it is mentioned that if you don't pass "typed_keys" parameter, aggregation will return with the default name, but it is not happening while using java high level rest client. While I was debugging that, I found there is no "typed_keys" check is being performed while writing the key name and aggregation name always has "type#aggregation_name". How can, I stop getting the type name in aggregation names.
The class where this default functionality is written is (ParsedAggregation.java) at line 64.
The high-level REST client sets the typed_keys parameter internally. It is needed otherwise it does not know which class to parse the aggregation response into, as every type of aggregation corresponds to a different class. There is no way to disable this if you are using the high-level REST client, but it should be transparent. As far as I can see the getName method should return the aggregation name, without the type prefix. How are you retrieving the aggregation name from the returned object? Where do you see the complete type#name string returned?
Once query executes on Elasticsearch, I convert the whole response object to JSON string. There it comes as "type#name". The methods, I have tried to convert to JSON are:
Yes that is expected, the idea is that when you get back a parsed aggregation, you retrieve info from it through getters, hence you have getName and getType that are separate. If you do print it back to json, it is expected that type and name will be concatenated again as part of the name and that is not something that can be disabled.
Maybe you can expand on why you need to print out the response as json, why have the high-level client parse the json to java objects for you if you then print out again the json from it. You can as well use the low-level REST client, which does not set the typed_keys parameter and get the json response as-is.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.