Pages

Tuesday, February 20, 2018

How to print an elasticsearch query made through its Java client?

How to print an elasticsearch query made through its Java client?

Elasticsearch Java client uses TCP and default port 9300 to connect to the ES cluster and run the query, unlike the REST clients which uses HTTP protocol and the default 9200 port. So, making a query using the Java client sometimes makes the query unreadable as it is not in JSON, but Java code. However, there is an easy way to print the JSON query which the Java client is executing in the backend.

 

Following is the code snippet to achieve the same:

[java]
SearchRequestBuilder searchRequestBuilder = elasticSearchClient().prepareSearch(
"Your index name").setQuery(Your query here).setSize(100);
System.out.println(searchRequestBuilder.internalBuilder());
[/java]

No comments:

Post a Comment