# How to merge the result after multi search, then I can sort them like sorting in queryDSL?

**URL:** <https://discuss.elastic.co/t/how-to-merge-the-result-after-multi-search-then-i-can-sort-them-like-sorting-in-querydsl/17020>\
**Category:** Elasticsearch\
**Created:** [April 15, 2014, 8:15am UTC](https://discuss.elastic.co/t/how-to-merge-the-result-after-multi-search-then-i-can-sort-them-like-sorting-in-querydsl/17020 "2014-04-15T08:15:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yyh3011](https://avatars.discourse-cdn.com/v4/letter/y/6de8d8/32.png) [@yyh3011](https://discuss.elastic.co/u/yyh3011)\
**Post date:** [April 15, 2014, 8:15am UTC](https://discuss.elastic.co/t/how-to-merge-the-result-after-multi-search-then-i-can-sort-them-like-sorting-in-querydsl/17020/1 "2014-04-15T08:15:30Z")

</div>

I have a multi search like:

{"index" : "news"}  
{"query":{ "bool":{ "must":[{ "more\_like\_this\_field" : { "content"  
:{"like\_text" : "James", "min\_term\_freq":1, "max\_query\_terms" : 12}} }, {  
"match":{"topic":"Business"} }] }}, "from" : 0, "size" : 4}  
{"index" : "news"}  
{"query":{ "bool":{ "must":[{ "more\_like\_this\_field" : { "content"  
:{"like\_text" : "James", "min\_term\_freq":1, "max\_query\_terms" : 12}} }, {  
"match":{"topic":"Sport"} }] }}, "from" : 0, "size" : 2}

but the result is an array, I expect I can merge them, and sort them by  
date and \_score, is there a best way to do this?  
Can I sort them like in ES, adding " "sort" : [ { "date" : {"order" :  
"desc"} }]" ?

thanks  
johnson

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/e402e2cd-3097-486b-a4f7-bc2864114f33%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e402e2cd-3097-486b-a4f7-bc2864114f33%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [April 15, 2014, 10:30am UTC](https://discuss.elastic.co/t/how-to-merge-the-result-after-multi-search-then-i-can-sort-them-like-sorting-in-querydsl/17020/2 "2014-04-15T10:30:54Z")

</div>

Hi,

All that the multi-search can do is executing several search requests in a  
single HTTP request. If you want to have merged results for both topics,  
you either need to submit a single query that matches both topics (but  
there is no guarantee that you will have 4 of them in the business topic  
and 2 of them in the sport topic, the first thousand matches might just be  
about business), or on client side.

On Tue, Apr 15, 2014 at 10:15 AM, [yyh3011@gmail.com](mailto:yyh3011@gmail.com) wrote:

> I have a multi search like:
> 
> {"index" : "news"}  
> {"query":{ "bool":{ "must":[{ "more\_like\_this\_field" : { "content"  
> :{"like\_text" : "James", "min\_term\_freq":1, "max\_query\_terms" : 12}} },  
> { "match":{"topic":"Business"} }] }}, "from" : 0, "size" : 4}  
> {"index" : "news"}  
> {"query":{ "bool":{ "must":[{ "more\_like\_this\_field" : { "content"  
> :{"like\_text" : "James", "min\_term\_freq":1, "max\_query\_terms" : 12}} },  
> { "match":{"topic":"Sport"} }] }}, "from" : 0, "size" : 2}
> 
> but the result is an array, I expect I can merge them, and sort them by  
> date and \_score, is there a best way to do this?  
> Can I sort them like in ES, adding " "sort" : [ { "date" : {"order" :  
> "desc"} }]" ?
> 
> thanks  
> johnson
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/e402e2cd-3097-486b-a4f7-bc2864114f33%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e402e2cd-3097-486b-a4f7-bc2864114f33%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/e402e2cd-3097-486b-a4f7-bc2864114f33%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/e402e2cd-3097-486b-a4f7-bc2864114f33%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .
> 
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
Adrien Grand

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j4%3DnxdoUGC%3DsohKeTrg0Yej-5ivp91vO\_c%3DZeJQMOXjAg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j4%3DnxdoUGC%3DsohKeTrg0Yej-5ivp91vO_c%3DZeJQMOXjAg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:35am UTC](https://discuss.elastic.co/t/how-to-merge-the-result-after-multi-search-then-i-can-sort-them-like-sorting-in-querydsl/17020/3 "2017-07-06T01:35:50Z")

</div>


