Filter by associated model date

Can I create filters/facets for fields that are actually related items instead of directly on the main item?

For example, if you had music artists as the main search model, and each artist has associated albums, but I only want to search for albums released before 2000. There is no ‘released’ value on the artist itself, it’s on the associated album.

Hi there,

Thanks for reaching out!
I may very well be wrong, but from what I understand, you are thinking too much in term of “Relational Data Base Management System” (RDBMS).
Algolia doesn’t have support for relationships between records (objects), and you can’t perform things such as joins between to indexes.

When using Algolia it’s important to keep to things in mind:

  • A record must contains everything that is necessary for him to be displayed
  • An index is to be considered as a collection of searchable attributes (each of them being self contained, as per the first point)

In your case, I guess you have an “album” index and an “artist” index, and you want to search for “artists” using informations located in the “albums”. This is not possible.

What you will have to do, is to copy the information of each of the album inside your artists’ records, and then use Algolia filtering feature (https://www.algolia.com/doc/guides/searching/filtering/) in order to restrict by date of release.

Feel free to correct me if I misunderstood your use-case, and don’t hesitate to ask if you have more questions!

Regards,

Hey there,
I’m using graph.cool to sync the index, and it allows me to add the relationships as JSON, so the index is something like { artist: name: “Rolling Stones”, albums: [{ title: “Aftermath”, release: 1966 … }] }

So is there a way to facet/filter by nested JSON (rather than relationship)?

Hi there,

You can refer to nested field with a dotted notation: albums.release!

Hope this helps!