Records with lots of different fields

Hi there,

Our new site requires an index of products which share some fields but also have a lot of different fields depending on their product category.

For example, a product in the “televisions” category might have fields called “width, height, screen size, display panel, 4k” etc.

However, a product in the “refrigerators” category might have fields like “width, height, min temperature, cubic capacity, freezer included” etc.

You’ll notice that they share width and height but other fields are different.

I know that everything in Algolia has to be a flat record, but I also realise JSON can be nested, so I guess i’m asking the best way to set this up because if I just have a massive list of fields for every product type I could have hundreds of fields in total (but only about 10 used per record). Even if I nest the options in an options array for each product won’t this still be very difficult to manage in the Algolia interface (because finding the right options to show and search in a drop down list of hundreds of options is unwieldy)?

Additionally, I’d like the UI to be able to show counts of facets, so if you’re looking at a list of televisions I’d like to be able to show you a list of screen sizes with the number of results afterwards. E.g.

55" (23)
64" (8)
65" (3)
75" (1)

I’d love to hear from anybody who has done this with a potentially unlimited number of product options.

Many thanks.

Hello Jon,

I understand that you have question abour record “schema” and how it scales.

Algolia does support nested attributes (so not flat).

You can use facets with nested attributes: AlgoliaHelper: How to facet filter a nested array property

With this you could have a shared schema with “domain specific” fields, we don’t require any schema to contains all the fields even if they are configured.
So you could with something like this:

{
  "type": "refrigerators",
  "width": 100,
  "height": 80,
  "temperature": 10,
}

{
  "type": "tv",
  "width": 100,
  "height": 80,
  "screen": "oled",
}

{
  "attributesForFaceting": ["width", "height", "screen", "temperature"],
}

If you search:

  • without filter, it will facets over all width/height/screen/temperature
  • with filter tv, it will facets over all width/height/screen (because no tv contains “temperature”)
  • with filter refrigerators, it will facets over all width/height/temperature (because no refrigerators contains “screen”)

This is usually how it’s done, but you have more complexe alternatives if that does not achieve what you want.
Let me know if that answers your question.

Best Regards