4

假设我使用这样的代码:

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

如何查看发送到 Elasticsearch 的 json 请求是什么?

4

2 回答 2

10

在 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)
于 2015-07-01T13:02:29.293 回答
0

我没有找到通过 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"
    }
  }
}
于 2015-06-16T10:21:20.930 回答