# Set subtraction from original index to other index

**URL:** <https://discuss.elastic.co/t/set-subtraction-from-original-index-to-other-index/148158>\
**Category:** Elasticsearch\
**Created:** [September 11, 2018, 2:36pm UTC](https://discuss.elastic.co/t/set-subtraction-from-original-index-to-other-index/148158 "2018-09-11T14:36:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nuketro0p3r](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nuketro0p3r/32/32584_2.png) [@nuketro0p3r](https://discuss.elastic.co/u/nuketro0p3r)\
**Post date:** [September 11, 2018, 2:36pm UTC](https://discuss.elastic.co/t/set-subtraction-from-original-index-to-other-index/148158/1 "2018-09-11T14:36:29Z")

</div>

Is it possible to write a query like:

SELECT \* FROM ORIGINAL as O where O.\_id NOT IN (  
SELECT \_id FROM OTHER\_1  
);

I've tried looking on Google, the best that I could do is:

GET OTHER\_1/\_search  
{  
"query": {  
"match\_all": {}  
}  
}

GET ORIGINAL /\_search  
{  
"size": 100,  
"\_source": "tracking\_number",  
"query": {  
"bool": {  
"must\_not": {  
"terms": { "tracking\_number": [1] }  
}  
}  
}  
}

Original has 30k records. The Other\_1 has about 10k.

This query still doesn't find a perfect set subtraction based on my random sample.

Thanks

---

<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:** [October 9, 2018, 2:36pm UTC](https://discuss.elastic.co/t/set-subtraction-from-original-index-to-other-index/148158/2 "2018-10-09T14:36:35Z")

</div>

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