假设我使用这样的代码:
ElasticClient client = ...
client.execute{search in "places"->"cities" query "paris" start 5 limit 10}
如何查看发送到 Elasticsearch 的 json 请求是什么?
假设我使用这样的代码:
ElasticClient client = ...
client.execute{search in "places"->"cities" query "paris" start 5 limit 10}
如何查看发送到 Elasticsearch 的 json 请求是什么?
在 Elastic4s 1.6.2 中,您可以在多个请求上使用show typeclass 来获得等效的 JSON。
这很简单。
val req = search in "index" / "type" query "kate bush"
logger.debug(s"Search request ${req.show}")
该.show
方法将呈现 JSON 输出。它适用于大多数请求类型。
在 Elastic4s 5.2.0+ 中,您使用show
客户端上的方法。
val req = search("index" / "type").query("kate bush")
client.show(req)
我没有找到通过 elastic4s 客户端跟踪每个请求的内置功能,但是_builder
在 elastic4s 中有一个变量,您可以在执行请求之前使用它来打印请求:
println(search in "places"->"cities" query "paris" start 5 limit 10 _builder) toString
{
"from" : 5,
"size" : 10,
"query" : {
"query_string" : {
"query" : "paris"
}
}
}