How track json request sent to Elasticsearch via elastic4s client?

為{幸葍}努か 提交于 2019-12-10 15:26:40

问题


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?


回答1:


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)



回答2:


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"
    }
  }
}


来源:https://stackoverflow.com/questions/30864841/how-track-json-request-sent-to-elasticsearch-via-elastic4s-client

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!