# Search hits used as filter

**URL:** <https://discuss.elastic.co/t/search-hits-used-as-filter/119831>\
**Category:** Elasticsearch\
**Created:** [February 14, 2018, 3:25pm UTC](https://discuss.elastic.co/t/search-hits-used-as-filter/119831 "2018-02-14T15:25:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hrachya\_Yeghishyan](https://avatars.discourse-cdn.com/v4/letter/h/a9a28c/32.png) [@Hrachya\_Yeghishyan](https://discuss.elastic.co/u/Hrachya_Yeghishyan)\
**Post date:** [February 14, 2018, 3:25pm UTC](https://discuss.elastic.co/t/search-hits-used-as-filter/119831/1 "2018-02-14T15:25:19Z")

</div>

Hi all,

I wonder whether there is a feature in ES that allows to use search hits of an index as filters of a query on a completely different index.  
I'll try to describe what i need on an example, in order to be more clear.  
Assume I have two indices, called "First"(which contains arbitrary number of fields) and "Second"(containing only 1 field). Then I perform a search on the only field of the index "Second" and get some hits.  
**Is there a way to use those hits as filters on a query performed on the index "First"?**  
Please note that the field values are similar: i.e. there will be no issue related to the field values.

---

<div class="post-metadata">

**Author:** ![Ayush\_Mathur](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ayush_mathur/32/77134_2.png) [@Ayush\_Mathur](https://discuss.elastic.co/u/Ayush_Mathur)\
**Post date:** [February 14, 2018, 4:35pm UTC](https://discuss.elastic.co/t/search-hits-used-as-filter/119831/2 "2018-02-14T16:35:34Z")

</div>

Hi,  
I believe it's not possible via ES UI, i.e. Kibana. Although you can try with curl command to get the desired result.

---

<div class="post-metadata">

**Author:** ![Hrachya\_Yeghishyan](https://avatars.discourse-cdn.com/v4/letter/h/a9a28c/32.png) [@Hrachya\_Yeghishyan](https://discuss.elastic.co/u/Hrachya_Yeghishyan)\
**Post date:** [February 14, 2018, 4:50pm UTC](https://discuss.elastic.co/t/search-hits-used-as-filter/119831/3 "2018-02-14T16:50:03Z")

</div>

Thanks for the reply @Ayush_Mathur,  
actually that is what I'm interested in. I'm working with the Java API for ElasticSearch. And in case of knowing the way to do that with curl, I'll be able to easily apply it in my project as well.

---

<div class="post-metadata">

**Author:** ![Ayush\_Mathur](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ayush_mathur/32/77134_2.png) [@Ayush\_Mathur](https://discuss.elastic.co/u/Ayush_Mathur)\
**Post date:** [February 14, 2018, 4:58pm UTC](https://discuss.elastic.co/t/search-hits-used-as-filter/119831/4 "2018-02-14T16:58:29Z")

</div>

Try something like:

curl -s -XGET --user "$USER:$PASS" "$ES/$INDEX/\_search?pretty" -H "Content-Type: application/json"   
--data '{ "query": { "bool": { "must": [{ "match": { "field": "value" } }, { "range" : { "field": { "lte": "value", "gte": "value" } } }] } }, "size" : 10000, "\_source": ["field list goes here"] }'

For multiple indices, may be you can omit $INDEX and use --data '{"indices" : ["index1", "index2"], "query"..... (haven't tried this though)

(fix the brackets and indentation 🙂 )

---

<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:** [March 14, 2018, 4:58pm UTC](https://discuss.elastic.co/t/search-hits-used-as-filter/119831/5 "2018-03-14T16:58:36Z")

</div>

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