If you're using Algolia InstantSearch and need to group related facet values, like treating “turquoise”, “ocean”, and “sky” as variations of “blue”, this article explains the recommended approach.
Algolia doesn’t support dynamic grouping at query time, so grouping should be done during indexing.
There are two main ways to handle this:
1. Add a separate group attribute
Create an additional attribute (e.g., colorGroup) to represent the broader category. You can then facet on this attribute globally:
[
{
"objectID": "1",
"color": "turquoise",
"colorGroup": "blue"
},
{
"objectID": "2",
"color": "ocean",
"colorGroup": "blue"
},
{
"objectID": "3",
"color": "sky",
"colorGroup": "blue"
}
]
2. Include both the specific and grouped values in the same facet attribute
Alternatively, store both the specific color and its group in a single array. This allows users to filter by either the individual value or the group:
[
{
"objectID": "1",
"color": [ "turquoise", "blue" ]
},
{
"objectID": "2",
"color": [ "ocean", "blue" ]
},
{
"objectID": "3",
"color": [ "sky", "blue" ]
}
]
This method makes both the individual colors and the broader group ("blue") available in the facet list.