# Distinct multi search result

**URL:** <https://discuss.elastic.co/t/distinct-multi-search-result/46862>\
**Category:** Elasticsearch\
**Created:** [April 9, 2016, 4:38am UTC](https://discuss.elastic.co/t/distinct-multi-search-result/46862 "2016-04-09T04:38:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gpong](https://avatars.discourse-cdn.com/v4/letter/g/d6d6ee/32.png) [@gpong](https://discuss.elastic.co/u/gpong)\
**Post date:** [April 9, 2016, 4:38am UTC](https://discuss.elastic.co/t/distinct-multi-search-result/46862/1 "2016-04-09T04:38:05Z")

</div>

Hi Guys,

I use Elasticsearch 2.2 and when using Multi Search API, it's possible to distinct the result between the first search and the second search??  
I have multi search query dsl like this

```
{}
{"query": {"filtered": {"filter": {"bool": {"must": [{"terms": {"mtart": ["roh"]}},{"terms": {"werks": ["f230","f232"]}}]}},"query": {"query_string": {"query": "roh"}}}}}
{}
{"query":{"filtered":{"filter":{"bool":{"must":[{"terms":{"mtart":["roh","nlag"]}},{"terms":{"werks":["f230","f231"]}}]}},"query":{"query_string":{"query":"roh"}}}}}

```

The result for the first search is 12 hits and the second is 39 hits. But there is duplicate value between first search and second search. And I want to distinct all the hits and get the unique documents. It is possible to do it??

Thanks a lot

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [April 10, 2016, 9:54am UTC](https://discuss.elastic.co/t/distinct-multi-search-result/46862/2 "2016-04-10T09:54:27Z")

</div>

Not using the APIs, no.  
You'd need to do that external to ES, in your own code.

---

<div class="post-metadata">

**Author:** ![gpong](https://avatars.discourse-cdn.com/v4/letter/g/d6d6ee/32.png) [@gpong](https://discuss.elastic.co/u/gpong)\
**Post date:** [April 11, 2016, 2:29am UTC](https://discuss.elastic.co/t/distinct-multi-search-result/46862/3 "2016-04-11T02:29:31Z")

</div>

Thanks Mark.

It there any possibility to use multisearch query string on JAVA API?? like setExtraSource function?  
I just need to input query string to the function and I can get the result.  
If I use for loop to create SearchBuilder, how to add to esClient.prepareMultiSearch().add(searchBuilder) function?

Thanks a lot

---

<div class="post-metadata">

**Author:** ![GavinSong123](https://avatars.discourse-cdn.com/v4/letter/g/46a35a/32.png) [@GavinSong123](https://discuss.elastic.co/u/GavinSong123)\
**Post date:** [March 29, 2017, 9:39am UTC](https://discuss.elastic.co/t/distinct-multi-search-result/46862/4 "2017-03-29T09:39:57Z")

</div>

I have the same problem. But the version of elasticsearch which I used is 5.2.2.

---

<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 5, 2017, 10:01pm UTC](https://discuss.elastic.co/t/distinct-multi-search-result/46862/5 "2017-07-05T22:01:47Z")

</div>


