# How can I combine two elasticsearch responses into one?

**URL:** <https://discuss.elastic.co/t/how-can-i-combine-two-elasticsearch-responses-into-one/19100>\
**Category:** Elasticsearch\
**Created:** [August 5, 2014, 6:19pm UTC](https://discuss.elastic.co/t/how-can-i-combine-two-elasticsearch-responses-into-one/19100 "2014-08-05T18:19:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jesse\_Russell](https://avatars.discourse-cdn.com/v4/letter/j/e8c25b/32.png) [@Jesse\_Russell](https://discuss.elastic.co/u/Jesse_Russell)\
**Post date:** [August 5, 2014, 6:19pm UTC](https://discuss.elastic.co/t/how-can-i-combine-two-elasticsearch-responses-into-one/19100/1 "2014-08-05T18:19:45Z")

</div>

I am currently stuck with a result response from a multi-search that  
returns an array of responses for each query I add, but I need the  
responses to be combined so that the relevancy to determine their order.  
Getting back two separated lists of hits isn't great for creating a unified  
search results page.

My current code for searching is:

SearchRequestBuilder srb1 = client.prepareSearch(category)  
.setSearchType(SearchType.QUERY\_THEN\_FETCH)  
.setQuery(QueryBuilders.queryString(query).field("body").field("title").field("author")  
.addHighlightedField("body").addHighlightedField("title").addHighlightedField("author")  
.setHighlighterPreTags("

").setHighlighterPostTags("
");  
SearchRequestBuilder srb2 = client.prepareSearch(category+"\_pdfs")  
.setSearchType(SearchType.QUERY\_THEN\_FETCH)  
.setQuery(  
QueryBuilders.queryString(query)  
.field("file")  
.field("title")  
.field("author")  
)  
.addHighlightedField("file").addHighlightedField("title").addHighlightedField("author")  
.setHighlighterPreTags("
").setHighlighterPostTags("
");  
MultiSearchResponse sr = client.prepareMultiSearch()  
.add(srb1)  
.add(srb2)  
.execute().actionGet();

Thanks for any help you all can give!

--  
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/a309df1d-77a7-4450-ae41-e286054e6bda%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a309df1d-77a7-4450-ae41-e286054e6bda%40googlegroups.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:10am UTC](https://discuss.elastic.co/t/how-can-i-combine-two-elasticsearch-responses-into-one/19100/2 "2017-07-06T01:10:40Z")

</div>


