# How to set a global search type in Multi Search API?

**URL:** <https://discuss.elastic.co/t/how-to-set-a-global-search-type-in-multi-search-api/10218>\
**Category:** Elasticsearch\
**Created:** [January 3, 2013, 1:21pm UTC](https://discuss.elastic.co/t/how-to-set-a-global-search-type-in-multi-search-api/10218 "2013-01-03T13:21:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ashraf\_Sarhan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ashraf_sarhan/32/2360_2.png) [@Ashraf\_Sarhan](https://discuss.elastic.co/u/Ashraf_Sarhan)\
**Post date:** [January 3, 2013, 1:21pm UTC](https://discuss.elastic.co/t/how-to-set-a-global-search-type-in-multi-search-api/10218/1 "2013-01-03T13:21:20Z")

</div>

I'm playing with the Multi Search API to get a response which contains a  
bulk of counts search requests and i want set the search\_type=count to  
globally apply to all search requests.

I tried to set the search\_type on the request header like that the below  
but it does not work, it works only when i put it in the header of each  
request in my bulk-request file (i mean that i had to duplicate that _{"search\_type"  
: "count"}_ in each header )

_curl -XGET [http://localhost:9200/\_msearch?pretty=1&search\_type=count](http://localhost:9200/_msearch?pretty=1&search_type=count)  
--data-binary @bulk-request; echo_

Any suggestions ??

--

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [January 3, 2013, 2:50pm UTC](https://discuss.elastic.co/t/how-to-set-a-global-search-type-in-multi-search-api/10218/2 "2013-01-03T14:50:46Z")

</div>

Hi Ashraf

On Thu, 2013-01-03 at 05:21 -0800, Ashraf Sarhan wrote:

> I'm playing with the Multi Search API to get a response which contains  
> a bulk of counts search requests and i want set the search\_type=count  
> to globally apply to all search requests.
> 
> I tried to set the search\_type on the request header like that the  
> below but it does not work, it works only when i put it in the header  
> of each request in my bulk-request file (i mean that i had to  
> duplicate that {"search\_type" : "count"} in each header )
> 
> curl -XGET [http://localhost:9200/\_msearch?pretty=1&search\_type=count](http://localhost:9200/_msearch?pretty=1&search_type=count)  
> --data-binary @bulk-request; echo

You're probably missing the "search metadata" line before each query:

curl -XGET '[http://127.0.0.1:9200/test/test/\_msearch?pretty=1&search\_type=count](http://127.0.0.1:9200/test/test/_msearch?pretty=1&search_type=count)' -d '  
{}  
{"query" : {"match\_all" : {}}}  
{}  
{"query" : {"match\_all" : {}}}  
'

# [Thu Jan 3 15:49:32 2013] Response:

# {

# "responses" : [

# {

# "hits" : {

# "hits" : ,

# "max\_score" : 0,

# "total" : 1

# },

# "timed\_out" : false,

# "\_shards" : {

# "failed" : 0,

# "successful" : 5,

# "total" : 5

# },

# "took" : 0

# },

# {

# "hits" : {

# "hits" : ,

# "max\_score" : 0,

# "total" : 1

# },

# "timed\_out" : false,

# "\_shards" : {

# "failed" : 0,

# "successful" : 5,

# "total" : 5

# },

# "took" : 1

# }

# ]

# }

clint

--

---

<div class="post-metadata">

**Author:** ![Ashraf\_Sarhan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ashraf_sarhan/32/2360_2.png) [@Ashraf\_Sarhan](https://discuss.elastic.co/u/Ashraf_Sarhan)\
**Post date:** [January 3, 2013, 3:58pm UTC](https://discuss.elastic.co/t/how-to-set-a-global-search-type-in-multi-search-api/10218/3 "2013-01-03T15:58:20Z")

</div>

Big Thanks, Clinton 🙂 It's working now.

On Thursday, January 3, 2013 4:50:46 PM UTC+2, Clinton Gormley wrote:

> Hi Ashraf
> 
> On Thu, 2013-01-03 at 05:21 -0800, Ashraf Sarhan wrote:
> 
> > I'm playing with the Multi Search API to get a response which contains  
> > a bulk of counts search requests and i want set the search\_type=count  
> > to globally apply to all search requests.
> > 
> > I tried to set the search\_type on the request header like that the  
> > below but it does not work, it works only when i put it in the header  
> > of each request in my bulk-request file (i mean that i had to  
> > duplicate that {"search\_type" : "count"} in each header )
> > 
> > curl -XGET [http://localhost:9200/\_msearch?pretty=1&search\_type=count](http://localhost:9200/_msearch?pretty=1&search_type=count)  
> > --data-binary @bulk-request; echo
> 
> You're probably missing the "search metadata" line before each query:
> 
> curl -XGET '  
> [http://127.0.0.1:9200/test/test/\_msearch?pretty=1&search\_type=count](http://127.0.0.1:9200/test/test/_msearch?pretty=1&search_type=count)' -d  
> '  
> {}  
> {"query" : {"match\_all" : {}}}  
> {}  
> {"query" : {"match\_all" : {}}}  
> '
> 
> # [Thu Jan 3 15:49:32 2013] Response:
> 
> # {
> 
> # "responses" : [
> 
> # {
> 
> # "hits" : {
> 
> # "hits" : ,
> 
> # "max\_score" : 0,
> 
> # "total" : 1
> 
> # },
> 
> # "timed\_out" : false,
> 
> # "\_shards" : {
> 
> # "failed" : 0,
> 
> # "successful" : 5,
> 
> # "total" : 5
> 
> # },
> 
> # "took" : 0
> 
> # },
> 
> # {
> 
> # "hits" : {
> 
> # "hits" : ,
> 
> # "max\_score" : 0,
> 
> # "total" : 1
> 
> # },
> 
> # "timed\_out" : false,
> 
> # "\_shards" : {
> 
> # "failed" : 0,
> 
> # "successful" : 5,
> 
> # "total" : 5
> 
> # },
> 
> # "took" : 1
> 
> # }
> 
> # ]
> 
> # }
> 
> clint

--

---

<div class="post-metadata">

**Author:** ![Ashraf\_Sarhan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ashraf_sarhan/32/2360_2.png) [@Ashraf\_Sarhan](https://discuss.elastic.co/u/Ashraf_Sarhan)\
**Post date:** [January 7, 2013, 7:02pm UTC](https://discuss.elastic.co/t/how-to-set-a-global-search-type-in-multi-search-api/10218/4 "2013-01-07T19:02:27Z")

</div>

Thanks a lot Clinton 🙂

Ashraf

On Thursday, January 3, 2013 4:50:46 PM UTC+2, Clinton Gormley wrote:

> Hi Ashraf
> 
> On Thu, 2013-01-03 at 05:21 -0800, Ashraf Sarhan wrote:
> 
> > I'm playing with the Multi Search API to get a response which contains  
> > a bulk of counts search requests and i want set the search\_type=count  
> > to globally apply to all search requests.
> > 
> > I tried to set the search\_type on the request header like that the  
> > below but it does not work, it works only when i put it in the header  
> > of each request in my bulk-request file (i mean that i had to  
> > duplicate that {"search\_type" : "count"} in each header )
> > 
> > curl -XGET [http://localhost:9200/\_msearch?pretty=1&search\_type=count](http://localhost:9200/_msearch?pretty=1&search_type=count)  
> > --data-binary @bulk-request; echo
> 
> You're probably missing the "search metadata" line before each query:
> 
> curl -XGET '  
> [http://127.0.0.1:9200/test/test/\_msearch?pretty=1&search\_type=count](http://127.0.0.1:9200/test/test/_msearch?pretty=1&search_type=count)' -d  
> '  
> {}  
> {"query" : {"match\_all" : {}}}  
> {}  
> {"query" : {"match\_all" : {}}}  
> '
> 
> # [Thu Jan 3 15:49:32 2013] Response:
> 
> # {
> 
> # "responses" : [
> 
> # {
> 
> # "hits" : {
> 
> # "hits" : ,
> 
> # "max\_score" : 0,
> 
> # "total" : 1
> 
> # },
> 
> # "timed\_out" : false,
> 
> # "\_shards" : {
> 
> # "failed" : 0,
> 
> # "successful" : 5,
> 
> # "total" : 5
> 
> # },
> 
> # "took" : 0
> 
> # },
> 
> # {
> 
> # "hits" : {
> 
> # "hits" : ,
> 
> # "max\_score" : 0,
> 
> # "total" : 1
> 
> # },
> 
> # "timed\_out" : false,
> 
> # "\_shards" : {
> 
> # "failed" : 0,
> 
> # "successful" : 5,
> 
> # "total" : 5
> 
> # },
> 
> # "took" : 1
> 
> # }
> 
> # ]
> 
> # }
> 
> clint

--

---

<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:** [July 6, 2017, 2:57am UTC](https://discuss.elastic.co/t/how-to-set-a-global-search-type-in-multi-search-api/10218/5 "2017-07-06T02:57:33Z")

</div>


