Log requests

Hi,
I'm migrating from the High Level Rest Client to Java Client and have problem to log the requests that are sent to ES.
I'm not using direct query, but somethink like this:

final var countRequest = new CountRequest.Builder()
        .index("myindex")
        .query(Query.of(b -> b.matchAll(QueryBuilders.matchAll().build())))
        .build();

Can I see somewhere the real query? Something like

POST myindex/_count
{
  "query": {
    "match_all": {}
  }
}

Thanks,
L.

Maybe, logging the query would be suffient, for High Level Rest Client this was very easy:

final var s = new SearchSourceBuilder().query(QueryBuilders.matchAllQuery()).toString();

in the s we've got

{"query":{"match_all":{"boost":1.0}}}

When I do QueryBuilders.matchAll().toString() for Java Client, I'm getting co.elastic.clients.elasticsearch._types.query_dsl.MatchAllQuery$Builder@ab7948b :frowning:

I've found a way. It's not very elegant, but works:

final JsonpMapper mapper = client._transport().jsonpMapper();

final StringWriter writer = new StringWriter();
try (final JsonGenerator generator = mapper.jsonProvider().createGenerator(writer)) {
    mapper.serialize(searchResponse, generator);
}
final String log = writer.toString();

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.