# Intersectional search from two indices

**URL:** <https://discuss.elastic.co/t/intersectional-search-from-two-indices/170643>\
**Category:** Elasticsearch\
**Created:** [March 3, 2019, 3:53pm UTC](https://discuss.elastic.co/t/intersectional-search-from-two-indices/170643 "2019-03-03T15:53:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![IgorPhoenix](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igorphoenix/32/78623_2.png) [@IgorPhoenix](https://discuss.elastic.co/u/IgorPhoenix)\
**Post date:** [March 3, 2019, 3:53pm UTC](https://discuss.elastic.co/t/intersectional-search-from-two-indices/170643/1 "2019-03-03T15:53:35Z")

</div>

I have two indices in Elastic: Track and Messages.  
Each index has ServiceId field.

Search in the Tracks index is always performed by fields (exact value) in the index.  
Search in the Messages is always performed by free text search in the index.

I need to implement an intersectional search from the both indices. To find ServiceIds from Tracks index by exact fields values and then find ServiceIds from Messages index by free text search and then to intersect the results = array of ServiceIds.

The actual result to the user is the list of Tracks by these ServiceIds received from the intersect action.

How can I do it? Each search (from Tracks and Messages) should return all the documents and only then intersect should be performed but as I understand Elastic can not return all the documents (suppose I have hundred of millions documents in each index) and intersect action is not correct...

![111](https://us1.discourse-cdn.com/elastic/original/3X/6/6/66a07ea2172cc39a5abc9d76bec7002e31517d5a.png)

---

<div class="post-metadata">

**Author:** ![IgorPhoenix](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igorphoenix/32/78623_2.png) [@IgorPhoenix](https://discuss.elastic.co/u/IgorPhoenix)\
**Post date:** [March 5, 2019, 6:18am UTC](https://discuss.elastic.co/t/intersectional-search-from-two-indices/170643/2 "2019-03-05T06:18:40Z")

</div>

Still help needed...

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [March 5, 2019, 6:24am UTC](https://discuss.elastic.co/t/intersectional-search-from-two-indices/170643/3 "2019-03-05T06:24:35Z")

</div>

This sounds like a join, which Elasticsearch does not support. I therefore suspect you will need to run two separate queries and merge the data in your application.

---

<div class="post-metadata">

**Author:** ![IgorPhoenix](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igorphoenix/32/78623_2.png) [@IgorPhoenix](https://discuss.elastic.co/u/IgorPhoenix)\
**Post date:** [March 5, 2019, 6:51am UTC](https://discuss.elastic.co/t/intersectional-search-from-two-indices/170643/4 "2019-03-05T06:51:28Z")

</div>

Hi Christian,  
You are right - it's a join. But my problem is that the result from the first search and from the second one can get correct ServiceId but when I join (intersect) them I get zero documents result.  
Is my explanation clear? If not, I'll try one more time...

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 5, 2019, 7:04am UTC](https://discuss.elastic.co/t/intersectional-search-from-two-indices/170643/5 "2019-03-05T07:04:02Z")

</div>

You need to share the exact queries you are running and the mapping.

---

<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:** [April 2, 2019, 7:09am UTC](https://discuss.elastic.co/t/intersectional-search-from-two-indices/170643/6 "2019-04-02T07:09:11Z")

</div>

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