Nested query in algolia

node
#1

Hi team,
I have a JSON structure like this. How can i query using this attribute (4549846717643) and get the quantity.

Let me know is it possible to nest an object like this in algolia.

simple_products: {
‘4549846717643’: {
size: {
eu: ‘36’,
uk: ‘3.5’,
us: ‘5.5’
},
quantity: ‘100’
},
‘4549846717681’: {
size: {
eu: ‘37.5’,
uk: ‘4.5’,
us: ‘6.5’
},
quantity: ‘56’
}
}

#2

Hi there, you can’t directly target this part of your JSON. You need to either get the root object first using https://www.algolia.com/doc/api-reference/api-methods/get-objects/ and then take what you want from it.

Or revisit your index structure and put every simple_products subobject into its own object/record in Algolia where 4549846717643 would be the objectID.

You can then use the distinct parameter to group results: https://www.algolia.com/doc/guides/managing-results/refine-results/grouping/

good luck!

1 Like
#3

Hi @vvo thank you so much for your reply.