Nested query in algolia

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’
}
}

1 Like

Hi there, you can’t directly target this part of your JSON. You need to either get the root object first using Get objects API Reference | Algolia 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: Grouping results | Algolia

good luck!

2 Likes

Hi @vvo thank you so much for your reply.

Hi, What if I wanted to do search query on one of the nested attributes ?
Like for example if my Json structure like this -

{
"objectID": 123,
“metaData”: {
            {
                 “dimension”: “16:9”,
                “number_of_scenes”: 2,
                “text_inside_block”: [
                    “ABC”,
                    “XYZ”,
                ],
                “duration”: 14.517
            },
            {
                 “dimension”: “9:16",
                “number_of_scenes”: 2,
                “text_inside_block”: [
                    “ABCD”,
                    “XYZA”,
                ],
                “duration”: 13.517
            }
        },
}

And I wanted to make metaData.text_inside_block a searchable attribute. But a conditional one. Like if query also matches metaData.dimension. Then search corresponding metaData.text_inside_block

Is it possible via Dashboard in Algolia or api client to set it as a rule ?