# Hide index result if result is in another index

**URL:** <https://discuss.elastic.co/t/hide-index-result-if-result-is-in-another-index/149290>\
**Category:** Elasticsearch\
**Created:** [September 20, 2018, 12:37pm UTC](https://discuss.elastic.co/t/hide-index-result-if-result-is-in-another-index/149290 "2018-09-20T12:37:30Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kurzer\_Patrick](https://avatars.discourse-cdn.com/v4/letter/k/9de053/32.png) [@Kurzer\_Patrick](https://discuss.elastic.co/u/Kurzer_Patrick)\
**Post date:** [September 20, 2018, 12:37pm UTC](https://discuss.elastic.co/t/hide-index-result-if-result-is-in-another-index/149290/1 "2018-09-20T12:37:30Z")

</div>

Hi everybody,

I try to get the following working:

Lets say I have two indices `region` and `theme`. Both of the indices have a field `name` and both indexed a String named `Vienna`.

At the moment if I search for `Vienna` I get both results. But in a new requirement I need to show just the `region` result (or hide the `theme` result) if the search Term (or the result) is **the**  **same** in `region` and `theme`.

Is there any way to do that? If you need more information please let me know.  
Thanks in advance.

---

<div class="post-metadata">

**Author:** ![johnrabi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/johnrabi/32/67223_2.png) [@johnrabi](https://discuss.elastic.co/u/johnrabi)\
**Post date:** [September 20, 2018, 12:47pm UTC](https://discuss.elastic.co/t/hide-index-result-if-result-is-in-another-index/149290/2 "2018-09-20T12:47:05Z")

</div>

There are two ways ,  
you need to search with one index (region) - you can get the result of this that index(region) only

another way you can restrict based on the index

may i know which language your using indexing purpose?

---

<div class="post-metadata">

**Author:** ![Kurzer\_Patrick](https://avatars.discourse-cdn.com/v4/letter/k/9de053/32.png) [@Kurzer\_Patrick](https://discuss.elastic.co/u/Kurzer_Patrick)\
**Post date:** [September 20, 2018, 12:58pm UTC](https://discuss.elastic.co/t/hide-index-result-if-result-is-in-another-index/149290/3 "2018-09-20T12:58:43Z")

</div>

Thanks for your response.

I need to search fo both indices because just on the result I need to hide `theme` results.

I use java for indexing and query.

---

<div class="post-metadata">

**Author:** ![johnrabi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/johnrabi/32/67223_2.png) [@johnrabi](https://discuss.elastic.co/u/johnrabi)\
**Post date:** [September 20, 2018, 1:10pm UTC](https://discuss.elastic.co/t/hide-index-result-if-result-is-in-another-index/149290/4 "2018-09-20T13:10:05Z")

</div>

In the result of response are you getting index name and type , based on that you can set the response and return that one in backend .

---

<div class="post-metadata">

**Author:** ![Kurzer\_Patrick](https://avatars.discourse-cdn.com/v4/letter/k/9de053/32.png) [@Kurzer\_Patrick](https://discuss.elastic.co/u/Kurzer_Patrick)\
**Post date:** [September 20, 2018, 1:15pm UTC](https://discuss.elastic.co/t/hide-index-result-if-result-is-in-another-index/149290/5 "2018-09-20T13:15:52Z")

</div>

I now I can have some business logic on my result. But I search for a solution for the query. Do you now if this is possible and which "technique" I need to use for the query?

---

<div class="post-metadata">

**Author:** ![johnrabi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/johnrabi/32/67223_2.png) [@johnrabi](https://discuss.elastic.co/u/johnrabi)\
**Post date:** [September 20, 2018, 1:31pm UTC](https://discuss.elastic.co/t/hide-index-result-if-result-is-in-another-index/149290/6 "2018-09-20T13:31:10Z")

</div>

hi ,

can you try this one

```auto
SearchResponse searchResponse = client.search(searchRequest);
        SearchHits hits = searchResponse.getHits();
        SearchHit[] searchHits = hits.getHits();
       for (SearchHit hit : searchHits) {
            System.out.println(hit.getIndex()

}
based on (hit.getIndex()) you can restrict
```

---

<div class="post-metadata">

**Author:** ![Kurzer\_Patrick](https://avatars.discourse-cdn.com/v4/letter/k/9de053/32.png) [@Kurzer\_Patrick](https://discuss.elastic.co/u/Kurzer_Patrick)\
**Post date:** [September 20, 2018, 2:17pm UTC](https://discuss.elastic.co/t/hide-index-result-if-result-is-in-another-index/149290/7 "2018-09-20T14:17:54Z")

</div>

Sorry, again I want to to that while query time. Not from the searchHits.

---

<div class="post-metadata">

**Author:** ![pmusa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pmusa/32/3498_2.png) [@pmusa](https://discuss.elastic.co/u/pmusa)\
**Post date:** [September 21, 2018, 11:48am UTC](https://discuss.elastic.co/t/hide-index-result-if-result-is-in-another-index/149290/8 "2018-09-21T11:48:53Z")

</div>

You cannot do that in a single query using only Elasticsearch logic. Documents are independent during query execution.

---

<div class="post-metadata">

**Author:** ![Kurzer\_Patrick](https://avatars.discourse-cdn.com/v4/letter/k/9de053/32.png) [@Kurzer\_Patrick](https://discuss.elastic.co/u/Kurzer_Patrick)\
**Post date:** [September 21, 2018, 12:26pm UTC](https://discuss.elastic.co/t/hide-index-result-if-result-is-in-another-index/149290/9 "2018-09-21T12:26:26Z")

</div>

Thanks Pablo.

So I need to index my stuff in another way to get it working. 😖

---

<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 19, 2018, 12:26pm UTC](https://discuss.elastic.co/t/hide-index-result-if-result-is-in-another-index/149290/10 "2018-10-19T12:26:41Z")

</div>

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