Multiple Indexes - ONE list output

Is it possible to combine results from multiple indexes into one list / template?

I’ve seen this: Multi-Index Search | Building Search UI | Guide | Algolia Documentation

Splitting it in two lists is great yeah - but what if I need to query multiple indexes, in one result set, say sorted by date, what do I do then?

1 Like

Hi @davidstellini. I’m curious to know more about your use case. I don’t believe it’s possible to combine two different indices the way you’re hoping. Technically both indices could have different ranking strategies and could conflict in the way the results should be ranked.

That being said, depending on what you’re hoping to do, there may be other strategies we can talk through.

This doc is a pretty good (and short) walkthrough of the question of 1 vs. many indices: Choosing Between One or More Indices | In depth | Sending and Managing Data | Guide | Algolia Documentation

I am using algolia with the firebase extension. I have two collections, that are rendered in one list. I need to search in that list. Results should be sorted by created date, a field common to both collections. There are no other ranking criteria

I would prefer to continue using the firebase extension for simplicity.

I’d still be curious to hear more about those collections, but I do see the issue (the extension automatically making indices based on collections even if it would be better served as one index).

I chatted with our support team a bit to make sure my assumptions were right. There IS a way of doing this, but it’s not necessarily a “simple” solution. Basically, you can create an index that aggregates the two separate indices and then use that. Here’s the response in a bit more completion:

That said, if you’d like to merge results from different indices you could create an aggregated index which holds the records from the original separated indices. The records in the aggregate index could be a lightweight version, which have only the attributes necessary for relevance in this aggregated drop-down. I.e. if you’d only like to take into consideration textual ranking criteria here for relevance and not use the various custom rankings, (which may not be on the same scale), these attributes would not need to be indexed.

In order to make sure that searchable attribute hierarchies from the different indices are taken into account, you will need to declare searchable attributes from each index are on the same “tier” as they were originally. So if “title” is the top searchable attribute for the business descriptions, it should also be at the top for the aggregated index, alongside any other “top” searchable attributes. Otherwise, if searchable attributes from one type are all stacked at the top of the searchable attributes list, then results will be skewed towards these.

In terms of UX, it would probably still be best to have a tag or icon on the display of each result to indicate what type of result it is, even if they are intermingled. The major drawback of this method is of course that duplicate versions of each record will be necessary – one in the original index and one in the aggregate index. There will also be the additional cost of keeping the aggregated index up to date.

I’m passing this frustration along to our integrations team, too. It would be nice if there was a way to have multiple (similar) collections aggregate into 1 index instead of defaulting to every collection going into a separate index. Any use-case details will help me write this up for the team, so I appreciate any details you can go into in how your data is set up (types of data and the end use case, etc.)

1 Like

Thanks for that - this was the first workaround I thought of: maintaining firebase triggers for onWrite and onDelete to sync up those two collections with one that algolia can then index. However, this is unnecessarily complicated (and also more expensive) when you consider that all the data is already inside algolia. In addition, I think you should improve your documentation on the subject:

For example, here: Multi-Index Search | Building Search UI | Guide | Algolia Documentation you talk about “Synchronising two indexes”.

This is not synchronizing or searching two indexes - this is the example for searching a single index, twice. “two ais search instances” ?

I came across the article when I was researching whether algolia was the right choice and felt misled as soon as I implemented it.

As for use case, I believe this is a super common one.
Take Instagram, for example. I want to search “Top results” , Latest, People, Videos.
Top, is a combination of all other four categories.

We have a similar problem in front of us and for now our only option is to tell the client we can’t have an “all” tab because algolia doesn’t support it, otherwise we have to run into super complicated workarounds.

1 Like

Another example of this use case is the Algolia Docs page, which searches across many different kinds of data (“Guide” is one heading, “Tutorial”, “How To” “Solution” Instantsearch Widget" are others).

Ideally one would like to say – fan this query out to these k indices and send me back an array of results. Once that’s possible, you could let users configure the relevant ranking strategies of each index within that sorted array…