Facet search array of objects #4461
-
We have a document structure like so: {
...
"tags": [
...
{ "id": "uuid", "value": "EUR", "type": "CURRENCY" }
...
]
...
} On our website we show three filter options. You can select one or multiple currencies, platforms (Steam, Amazon, etc) and target countries (Belgium, The Netherlands, etc). So we basically need to show each option in our selection list (uniquely). Right now we just did a search and gathered the data in code, but once we have a lot of documents this will be an issue, especially considering the fact we can't retrieve 10-20-30 thousand hits at once for every client visiting our website. So we went through the Meilisearch docs and we found facets. Facets seem to be perfect. We don't need hits so we just set the The problem however is that once we set How can we achieve what we want? What would be the best solution here and does Meilisearch even support this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hey @rauldeheer 👋 I understand your issue a little bit, but only some things. It seems to be related to this one in some way where a user wants to filter documents by using multiple fields of an object inside the main document.
That's what made me think about the above issue. Meilisearch flattens the subobjects in a document. It's like the objects in tags = [{ type: CURRENCY, value: EUR }, { type: PLATFORM, value: STEAM }]
// Becomes this. Sub-objects field relations are lost.
tags.type = [CURRENCY, PLATFORM], tags.value = [EUR, STEAM]
Would it make sense to split your types into different fields? I am thinking about something like the following to keep the relations together. When requesting facet distributions by using page 0, you'll get only the values associated with CURRENCY and no more STEAM value for it. You just need to ask about the facets distribution of "tagsCurrency": "EUR"
"tagsPlatform": "STEAM"
// or even that way
"tags": {
"CURRENCY": "EUR",
"PLATFORM": "STEAM",
} |
Beta Was this translation helpful? Give feedback.
Hey @rauldeheer 👋
I understand your issue a little bit, but only some things. It seems to be related to this one in some way where a user wants to filter documents by using multiple fields of an object inside the main document.
That's what made me think about the above issue. Meilisearch flattens the subobjects in a document. It's like the objects in
tags
see their fields explode and an array of the values lives in dedicatedtags.type
ortags.value
fields.