Search code examples
elasticsearchpostman

How to send elasticsearch multi search request in Postman?


I'm trying to send elasticserach multi search request via postman as below:

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

However, I'm getting following error:

{
  "error": {
    "root_cause": [
      {
        "type": "parse_exception",
        "reason": "Failed to derive xcontent"
      }
    ],
    "type": "parse_exception",
    "reason": "Failed to derive xcontent"
  },
  "status": 400
}

Note that if I perform same request via my play code, results are succesfully fetched.

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

Solution

  • Three things are important here:

    1. When inserting body, select raw radiobutton and Text (or JSON) from dropdown.
    2. Add header: Content-type: application/x-ndjson
    3. Most important: put new line after the last line of your query

    Body: enter image description here

    Header:

    enter image description here

    Curl version:

    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":{}}}
    '