Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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) 
like image 734
Ra Ka Avatar asked Aug 01 '17 11:08

Ra Ka


People also ask

How do I search Elasticsearch index?

You can use the search API to search and aggregate data stored in Elasticsearch data streams or indices. The API's query request body parameter accepts queries written in Query DSL. The following request searches my-index-000001 using a match query. This query matches documents with a user.id value of kimchy .

How do I connect to Elasticsearch API?

There are two ways to connect to your Elasticsearch cluster: Through the RESTful API or through the Java transport client. Both ways use an endpoint URL that includes a port, such as https://ec47fc4d2c53414e1307e85726d4b9bb.us-east-1.aws.found.io:9243 .


2 Answers

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":{}}} ' 
like image 142
Joanna Avatar answered Sep 23 '22 19:09

Joanna


You can also make your request body be json format and change your Content-Type be application/json, please take a look as below

Header with Content-Type

Your search request with json type

Response data

like image 22
Peter.Chu Avatar answered Sep 21 '22 19:09

Peter.Chu