【发布时间】:2015-09-01 02:38:17
【问题描述】:
说我用这样的代码:
ElasticClient client = ...
client.execute{search in "places"->"cities" query "paris" start 5 limit 10}
如何查看发送到 Elasticsearch 的 json 请求是什么?
【问题讨论】:
标签: json scala http elasticsearch elastic4s
说我用这样的代码:
ElasticClient client = ...
client.execute{search in "places"->"cities" query "paris" start 5 limit 10}
如何查看发送到 Elasticsearch 的 json 请求是什么?
【问题讨论】:
标签: json scala http elasticsearch elastic4s
在 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 客户端跟踪每个请求的内置功能,但是在 elastic4s 中有一个 _builder 变量,您可以在执行它之前使用它来打印请求:
println(search in "places"->"cities" query "paris" start 5 limit 10 _builder) toString
{
"from" : 5,
"size" : 10,
"query" : {
"query_string" : {
"query" : "paris"
}
}
}
【讨论】: