Search code examples
algoliainstantsearch.js

Filter for one attribute (array) for one of its value (json)


Having the following record

   {
      "name": "
 Festões Plástico, 12mt x 17cm - Festas Populares",
      "categories": [
        "Festas",
        "Casamentos",
        "Decorações"
      ],
      "hierarchicalCategories": {
        "lvl0": "Festas",
        "lvl1": "Festas > Casamentos",
        "lvl2": "Festas > Casamentos > Decorações"
      },
      "description": "",
      "brand": "Misterius",
      "price": 14.94,
      "stock": "Disponível",
      "prices": [
        {
          "value": 12,
          "type": "specificValue",
          "family": "fatos",
          "subfamily": "example"
        },
        {
          "value": 13,
          "type": "specificValue13",
          "family": "fatos13",
          "subfamily": "example13"
        },
        {
          "value": 14,
          "type": "specificValue14",
          "family": "fatos14",
          "subfamily": "example14"
        },
        {
          "value": 15,
          "type": "specificValue15",
          "family": "fatos15",
          "subfamily": "example15"
        },
        {
          "value": 16,
          "type": "specificValue16",
          "family": "fatos16",
          "subfamily": "example16"
        }
      ],
      "color": [
        {
          "name": "Amarelo",
          "label": "Amarelo,#FFFF00",
          "hexa": "#FFFF00"
        },
        {
          "name": "Azul",
          "label": "Azul,#0000FF",
          "hexa": "#0000FF"
        },
        {
          "name": "Branco",
          "label": "Branco,#FFFFFF",
          "hexa": "#FFFFFF"
        },
        {
          "name": "Laranja",
          "label": "Laranja,#FFA500",
          "hexa": "#FFA500"
        },
        {
          "name": "Verde Escuro",
          "label": "Verde Escuro,#006400",
          "hexa": "#006400"
        },
        {
          "name": "Vermelho",
          "label": "Vermelho,#FF0000",
          "hexa": "#FF0000"
        }
      ],
      "specialcategorie": "",
      "reference": "3546",
      "rating": 0,
      "free_shipping": false,
      "popularity": 0,
      "objectID": "30"
    }

Now by searching for "Festas Populares" will return the record and its attributes, is it possible to also filter for one attribute array as "prices" to only return one json. for example "prices.type"="specificValue14" and "family"="fatos14" and "family"="fatos" and "subfamily"="example"

{
“value”: 14,
“type”: “specificValue14”,
“family”: “fatos14”,
“subfamily”: “example14”
}

the record return would be:

 {
          "name": "
 Festões Plástico, 12mt x 17cm - Festas Populares",
          "categories": [
            "Festas",
            "Casamentos",
            "Decorações"
          ],
          "hierarchicalCategories": {
            "lvl0": "Festas",
            "lvl1": "Festas > Casamentos",
            "lvl2": "Festas > Casamentos > Decorações"
          },
          "description": "",
          "brand": "Misterius",
          "price": 14.94,
          "stock": "Disponível",
          "prices": [
            {
              "value": 14,
              "type": "specificValue14",
              "family": "fatos14",
              "subfamily": "example14"
            }
          ],
          "color": [
            {
              "name": "Amarelo",
              "label": "Amarelo,#FFFF00",
              "hexa": "#FFFF00"
            },
            {
              "name": "Azul",
              "label": "Azul,#0000FF",
              "hexa": "#0000FF"
            },
            {
              "name": "Branco",
              "label": "Branco,#FFFFFF",
              "hexa": "#FFFFFF"
            },
            {
              "name": "Laranja",
              "label": "Laranja,#FFA500",
              "hexa": "#FFA500"
            },
            {
              "name": "Verde Escuro",
              "label": "Verde Escuro,#006400",
              "hexa": "#006400"
            },
            {
              "name": "Vermelho",
              "label": "Vermelho,#FF0000",
              "hexa": "#FF0000"
            }
          ],
          "specialcategorie": "",
          "reference": "3546",
          "rating": 0,
          "free_shipping": false,
          "popularity": 0,
          "objectID": "30"
        }

for some context a product can have multiple prices associated, for a specific user, or one day there is campaign giving discount, etc so for that cases want to filter price associated to the product/record.


Solution

  • No, this is not possible with Algolia. Records are always returned with the attributes specified inside attributesToRetrieve. These attributes are returned in full.