Hide index result if result is in another index

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.

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?

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.

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 .

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?

hi ,

can you try this one

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

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

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

Thanks Pablo.

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

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