# Unable to use msearch using Curl or any Rest client

**URL:** <https://discuss.elastic.co/t/unable-to-use-msearch-using-curl-or-any-rest-client/109320>\
**Category:** Elasticsearch\
**Created:** [November 28, 2017, 7:21am UTC](https://discuss.elastic.co/t/unable-to-use-msearch-using-curl-or-any-rest-client/109320 "2017-11-28T07:21:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![niraj\_kumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/niraj_kumar/32/4130_2.png) [@niraj\_kumar](https://discuss.elastic.co/u/niraj_kumar)\
**Post date:** [November 28, 2017, 7:21am UTC](https://discuss.elastic.co/t/unable-to-use-msearch-using-curl-or-any-rest-client/109320/1 "2017-11-28T07:21:13Z")

</div>

Hi,

I got the my complex \_msearch query from chrome developer tools. I took the payload the the request URL and pasted that in the dev tools and it worked fine and gave me the same result i was looking for as kibana UI. As a use case i want to post this query to zabbix but that is a different topic. I want to call this using a program like python or bash script.

My search query looks like this:

```
{"index":["bigdata_prd-*"],"ignore_unavailable":true,"preference":1511829047717}
{"query":{"bool":{"must":[{"query_string":{"analyze_wildcard":true,"query":"raw_queue: \"test_k1_k8\""}},{"range":{"@timestamp":{"gte":1511742649613,"lte":1511829049613,"format":"epoch_millis"}}}],"must_not":[]}},"size":0,"_source":{"excludes":[]},"aggs":{"1":{"avg":{"field":"raw_payload_count_total"}}}}

```

So as you see these are two different json but Kibana is able to parse that properly and give me the correct value as required. I am not sure how it is parsing that. I tried using curl or postman and did a POST but it fails with a parse error

`{"error":{"root_cause":[{"type":"parse_exception","reason":"request body or source parameter is required"}],"type":"parse_exception","reason":"request body or source parameter is required"}`

How to make a \_msearch work with Curl .

--  
Niraj

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [November 28, 2017, 7:51am UTC](https://discuss.elastic.co/t/unable-to-use-msearch-using-curl-or-any-rest-client/109320/2 "2017-11-28T07:51:54Z")

</div>

Hey,

is your second line with the request JSON really ending with a newline? See the note in [https://www.elastic.co/guide/en/elasticsearch/reference/6.0/search-multi-search.html#search-multi-search](https://www.elastic.co/guide/en/elasticsearch/reference/6.0/search-multi-search.html#search-multi-search)

--Alex

---

<div class="post-metadata">

**Author:** ![niraj\_kumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/niraj_kumar/32/4130_2.png) [@niraj\_kumar](https://discuss.elastic.co/u/niraj_kumar)\
**Post date:** [November 28, 2017, 7:55am UTC](https://discuss.elastic.co/t/unable-to-use-msearch-using-curl-or-any-rest-client/109320/3 "2017-11-28T07:55:03Z")

</div>

Yes it does end with the new line.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [November 28, 2017, 7:58am UTC](https://discuss.elastic.co/t/unable-to-use-msearch-using-curl-or-any-rest-client/109320/4 "2017-11-28T07:58:09Z")

</div>

please share the **exact** curl query you executed, including all parameters

---

<div class="post-metadata">

**Author:** ![niraj\_kumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/niraj_kumar/32/4130_2.png) [@niraj\_kumar](https://discuss.elastic.co/u/niraj_kumar)\
**Post date:** [November 28, 2017, 8:02am UTC](https://discuss.elastic.co/t/unable-to-use-msearch-using-curl-or-any-rest-client/109320/5 "2017-11-28T08:02:44Z")

</div>

Please find it below:

```
curl -XGET "http://example.com/elasticsearch/bigdata_prd-2017*/_msearch?" -H 'Content-Type: application/json' -d'
{"index":["bigdata_prd-*"],"ignore_unavailable":true,"preference":1511831863818}
{"query":{"bool":{"must":[{"query_string":{"analyze_wildcard":true,"query":"raw_queue: \"test_k1_k8\""}},{"range":{"@timestamp":{"gte":1511745466067,"lte":1511831866067,"format":"epoch_millis"}}}],"must_not":[]}},"size":0,"_source":{"excludes":[]},"aggs":{"1":{"avg":{"field":"raw_payload_count_total"}}}}'
```

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [November 28, 2017, 8:21am UTC](https://discuss.elastic.co/t/unable-to-use-msearch-using-curl-or-any-rest-client/109320/6 "2017-11-28T08:21:51Z")

</div>

that example does not contain a newline in the second line, but contains an unnecessary newline right at the beginning.

can you try

```auto
curl -XGET "http://example.com/elasticsearch/bigdata_prd-2017*/_msearch?" -H 'Content-Type: application/json' -d'{"index":["bigdata_prd-*"],"ignore_unavailable":true,"preference":1511831863818}
{"query":{"bool":{"must":[{"query_string":{"analyze_wildcard":true,"query":"raw_queue: \"test_k1_k8\""}},{"range":{"@timestamp":{"gte":1511745466067,"lte":1511831866067,"format":"epoch_millis"}}}],"must_not":[]}},"size":0,"_source":{"excludes":[]},"aggs":{"1":{"avg":{"field":"raw_payload_count_total"}}}}
'

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 26, 2017, 8:22am UTC](https://discuss.elastic.co/t/unable-to-use-msearch-using-curl-or-any-rest-client/109320/7 "2017-12-26T08:22:36Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
