4

Say that I use such code:

ElasticClient client = ...
client.execute{search in "places"->"cities" query "paris" start 5 limit 10}

How to see what json request was been sent to Elasticsearch?

Andrei Stefan
  • 51,654
  • 6
  • 98
  • 89
Cherry
  • 31,309
  • 66
  • 224
  • 364

2 Answers2

10

In Elastic4s 1.6.2 you can use the show typeclass on a number of requests to get the JSON equivilent.

It's pretty straightforward.

val req = search in "index" / "type" query "kate bush"
logger.debug(s"Search request ${req.show}")

The .show method will render JSON output. It works on most of the request types.

In Elastic4s 5.2.0+, you use the show method on the client.

val req = search("index" / "type").query("kate bush")
client.show(req)
sksamuel
  • 16,154
  • 8
  • 60
  • 108
0

I did not find build-in feature to track every request via elastic4s client, but there is a _builder variable in elastic4s which you can use to print request before execute it:

println(search in "places"->"cities" query "paris" start 5 limit 10 _builder) toString

{
  "from" : 5,
  "size" : 10,
  "query" : {
    "query_string" : {
      "query" : "paris"
    }
  }
}
Cherry
  • 31,309
  • 66
  • 224
  • 364
  • This doesn't work for every request type. Version 1.6 will have a feature to log all queries (or most of them). The reason is that the java client doesn't turn things into json, but the other way around. The REST interface turns json into java calls internally. – sksamuel Jun 16 '15 at 16:05
  • Could you please provide example of non-working request? – Cherry Jun 18 '15 at 02:43
  • I can't remember but some of the less common ones don't output json (or at least they didn't when I first started elastic4s 2 years ago. Maybe they all do now). I'm going to add some logging to expose these anyway. – sksamuel Jun 18 '15 at 12:36
  • 1
    UpdateDsl is an example of one that you can't simply call toString on. – sksamuel Jun 28 '15 at 00:51