Best practices with how to structure an index

Is there a guide for how to best design indexes? I’m new to aloglia and don’t have experience for how different structures will play out.

  • Should I have separate indexes for each use case in our app. Where I might be able to repurpose an index by adding some additional fields, should I do that?

  • Should I try to put all the fields for a specific use case into a single index (which will leave some values in columns blank) or is it better to query across indexes?

Here’s my specific use cases, but I’m also asking more generally how do I see around the corner into what structures are better than others?

Use case #1: Enable users to search for other users in my groups OR other users who I’ve met. Is this one index (eg. combo of users in my groups + users who I’ve met in one index) or should I split this data out as two indexes similar to how this data is stored in our source database?

What might this look like as a single index?
user_id | group(y/n) | met(y/n)| other_user_id | other_user_fields ???

Use case #2: I have a similar search as use case #1 but now the users wants to search for notes she’s taken from meetings with specific people. Should I try to build this onto the other index?

user_id | group(y/n) | met(y/n)| other_user_id | other_user_fields | my_notes ???

What are the implications for maintaining the different structures?

Hi @kramwe,

Thanks for contacting Algolia - we’re excited that you are starting to use our API!

I’ll start off with general resources and highly recommend looking at our:

A few tips to address your specific questions, but please note that advanced use-case structures and ranking get direct guidance from our Solutions team at our Business and Enterprise plans.

Should I have separate indexes for each use case in our app. Where I might be able to repurpose an index by adding some additional fields, should I do that?

The general tip is to have a separate index for each separate type of data structure. Although Algolia is not a database, it might be helpful to think of having one index per database table/model you have.

Should I try to put all the fields for a specific use case into a single index (which will leave some values in columns blank) or is it better to query across indexes?

This depends and really can’t be answered in broad strokes! There are times when multi-queries are used, and other times when a single query will suffice.

Use case #1: Enable users to search for other users in my groups OR other users who I’ve met. Is this one index (eg. combo of users in my groups + users who I’ve met in one index) or should I split this data out as two indexes similar to how this data is stored in our source database?

Since Algolia is a schemaless database, the “relationships” you might have in your database do not exist and you need to create “flat” objects that contain all the relationships. So, yes, you are going down the right path in thinking of an object shape:

{
    "user_id": 1,
    "group": true,
    "met": true,
    "other_met_user_ids": [4,77,38,5],
    ... //anything else you want - Algolia is schemaless
}

Use case #2: I have a similar search as use case #1 but now the users wants to search for notes she’s taken from meetings with specific people. Should I try to build this onto the other index?

Similar to above, if you have a notes_index, then you might decide to reference the notes_ids in your user object:

{
    "user_id": 1,
    ... //anything else you want - Algolia is schemaless
   "notes_ids": [28, 5, 13]
}

What are the implications for maintaining the different structures?

Keep in mind the quotas of different plans for record size, indexing operations, and record counts

Happy coding with Algolia!