Priotitizing searching accross multiple Indices

Hi All,

I have multiple indices created in my elastic search. I am using 2.1.1 version. of ES.
My search requirement is like user will enter a keyword and search should happen against all indexes. But i want to prioritize the records returned. I mean ,I need only 10 matching records. From Index A i need 5 record, from index B i need 3 record, and from index C i need 2 record.
This is max count in case all indices fetch matching results. But in case index B and C doesn't have any matching record, i need all 10 from index A if it has more records. Similarly if there is no matching record from index B, then 8 record from index A and 2 record from index B should be returned.

Is this kind of segregation possible in ES?

Hi soorajhere,

I guess that you could do that by adding some logic (by logic i mean code) in Java for example and filter results as you wish. I am not aware of such a built-in feature in Elastic.

I am not aware of any way of doing this with a single query either, but you could send 3 separate queries, each returning 10 results, as part of a multi search request and then select the ones to use at the application layer.

I think index boost would help you. Not sure it will allow you to do exactly what you need, but something along those lines for sure. It is not a very popular feature but it's there: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-index-boost.html .

Cheers
Luca

1 Like

Hi illiasse,

Thank you for your reply.
I have created a wcf wrapper service in .net and is calling ElasticSearch REST API from this service. I also had similar thought of retrieving all results from ES and then do the filtering from .net code. But the search query which I use is a single multi_match query and I mention fields from multiple indexes in it. Also the search i need is a phrase_prefix search and i limit size to 10 in the query.
As you mentioned, if i do the filtering from .net code, i might have to get all search results(remove size from query?) from ES instead of limiting it to 10, right? I think ES by default return 10 hits, and if more results are required, we need to mention size value. But how can we have a particular value for size upfront? What if more matching search records are present? OR is it like i need to provide a huge number say, 10K or something?

Hi Christian_Dahlqvist ,
Thank you for your reply.
Is it a good idea to hit ES server multiple times with different search query? I thought performance will degrade using this method, so was trying to use fields property in the search query and mention fields from multiple indices in the query.

Hi Luca Cavanna,

Thank you for your reply. I will give a try with index boost.