# Log requests

**URL:** <https://discuss.elastic.co/t/log-requests/321216>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [December 14, 2022, 12:11pm UTC](https://discuss.elastic.co/t/log-requests/321216 "2022-12-14T12:11:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lubosvr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lubosvr/32/104400_2.png) [@lubosvr](https://discuss.elastic.co/u/lubosvr)\
**Post date:** [December 14, 2022, 12:11pm UTC](https://discuss.elastic.co/t/log-requests/321216/1 "2022-12-14T12:11:29Z")

</div>

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:

```auto
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

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

```

Thanks,  
L.

---

<div class="post-metadata">

**Author:** ![lubosvr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lubosvr/32/104400_2.png) [@lubosvr](https://discuss.elastic.co/u/lubosvr)\
**Post date:** [December 14, 2022, 5:37pm UTC](https://discuss.elastic.co/t/log-requests/321216/2 "2022-12-14T17:37:00Z")

</div>

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

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

```

in the `s` we've got

```auto
{"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` ☹

---

<div class="post-metadata">

**Author:** ![lubosvr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lubosvr/32/104400_2.png) [@lubosvr](https://discuss.elastic.co/u/lubosvr)\
**Post date:** [December 16, 2022, 7:29am UTC](https://discuss.elastic.co/t/log-requests/321216/3 "2022-12-16T07:29:00Z")

</div>

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

```auto
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();

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 13, 2023, 7:29am UTC](https://discuss.elastic.co/t/log-requests/321216/4 "2023-01-13T07:29:47Z")

</div>

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