Hide index result if result is in another index

(Kürzer Patrick) #1

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.

(john rabindranath) #2

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?

(Kürzer Patrick) #3

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.

(john rabindranath) #4

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 .

(Kürzer Patrick) #5

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?

(john rabindranath) #6

hi ,

can you try this one

SearchResponse searchResponse = client.search(searchRequest);
        SearchHits hits = searchResponse.getHits();
        SearchHit[] searchHits = hits.getHits();
       for (SearchHit hit : searchHits) {

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

(Kürzer Patrick) #7

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

(Pablo Musa) #8

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

(Kürzer Patrick) #9

Thanks Pablo.

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

(system) #10

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