如何在Postman中发送elasticsearch多搜索请求?

Ra *_* Ka 18 elasticsearch postman

我正在尝试通过postman发送elasticserach多搜索请求,如下所示:

POST - http://localhost:9200/_msearch
content-type : x-www-form-urlencoded
body:
{"index":"accounts"}
{"query":{"bool":{"should":[{"match":{"owner.first_name":"Creeple"}}]}}}
Run Code Online (Sandbox Code Playgroud)

但是,我收到以下错误:

{
  "error": {
    "root_cause": [
      {
        "type": "parse_exception",
        "reason": "Failed to derive xcontent"
      }
    ],
    "type": "parse_exception",
    "reason": "Failed to derive xcontent"
  },
  "status": 400
}
Run Code Online (Sandbox Code Playgroud)

请注意,如果我通过播放代码执行相同的请求,则会成功获取结果.

WS.url("localhost:9200/_msearch").withHeaders("Content-type" -> "application/x-www-form-urlencoded").post(query)
Run Code Online (Sandbox Code Playgroud)

Joa*_*nna 28

这里有三件事很重要:

  1. 插入主体时,从下拉列表中选择原始单选按钮和文本(或JSON).
  2. 添加标题:Content-type:application/x-ndjson
  3. 最重要的是:在查询的最后一行之后添加新行

身体: 在此输入图像描述

标题:

在此输入图像描述

卷曲版本:

curl -X POST \
  http://127.0.0.1:9200/_msearch \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/x-ndjson' \
  -d '{"index":"script","type":"test"}
{"query":{"match_all":{}}}
'
Run Code Online (Sandbox Code Playgroud)

  • 我缺少的一点是 json 应该被压缩成一行。不知道这是否愚蠢,但我确实因为 json 格式正确的问题而抓狂。我收到“意外的输入结束”错误 (3认同)

Pet*_*Chu 5

您还可以将请求正文设置为 json 格式,并将 Content-Type 更改为 application/json,请看下面

带有内容类型的标头

您的 json 类型的搜索请求

响应数据