I am using "opensearch-java:2.8.1". In the Elasticsearch java client, I was able to logging my query in the following way.
SearchRequest searchRequest = searchRequestBuilder.build();
log.info("query: {}", searchRequest.toString());
However, in the opensearch java client, the implementation of toString is different.
public String toString() {
return getClass().getName() + "@" + Integer.toHexString(hashCode());
}
Is there any way I can log a query?
The
toString()method you are referring to, comes fromObject.javaitself which is parent of all the classes in java. Since,SearchRequestis actually not overriding it, hence the the implementation is being taken fromObject.java.The implementation difference between
toString()comes from the fact that it is implemented in elasticsearch-java but not implemented in opensearch-java.Now coming to the issue of logging information from SearchRequest, you will need to use some other methods which can give you your desired info. For example I see
Or as per this stackoverflow answer, if you want to print query: