Filtering with a property that is an array of objects

Hello everyone, I’m having some trouble to manage to filter my records can anyone possibly help me out?

So my record has a property named accommodations, that is an array of objects that have the properties:

  • housing
  • roomType
  • meal
  • bathroom

Like the example bellow:

“id”: 999,
“country”: “Estados Unidos”,
“city”: “Fort Lauderdale”,
“programType”: “Curso de Idioma”,
“language”: “Inglês”,
“courseLoad”: “30 Aulas Semanais”,
“hour”: “Integral”,
“title”: “Intensive English”,
“accommodations”: [
{
“id”: 905,
“provider”: “Homestay”,
“name”: “Homestay”,
“housing”: “Casa de Família”,
“roomType”: “Individual”,
“meal”: "Café da Manhã ",
“bathroom”: “Externo Compartilhado”,
},
{
“id”: 906,
“provider”: “Homestay”,
“name”: “Homestay”,
“housing”: “Casa de Família”,
“roomType”: “Duplo”,
“meal”: "Café da Manhã ",
“bathroom”: “Externo Compartilhado”,
},
{
“id”: 907,
“provider”: “La Quinta”,
“name”: “La Quinta”,
“housing”: “Residência Estudantil”,
“roomType”: “Individual”,
“meal”: "Sem Refeição ",
“bathroom”: “Privativo”,
},
{
“id”: 908,
“provider”: “La Quinta”,
“name”: “La Quinta”,
“housing”: “Residência Estudantil”,
“roomType”: “Duplo”,
“meal”: “Sem Refeição”,
“bathroom”: “Internao Compartilhado”,
}
],

I’m able to create the filter for those properties, but when I filtered it, it will filter as an “OR” condition.
So for example, if I set the filter for housing as “Residência Estudantil” it will show all the records that has the accommodation.housing with “Residência Estudantil” but when I add a second filter, for meal for example with the value Café da Manhã it will still show this record because it is searching for any object inside the array of objects that has the meal field with “Café da Manhã” OR the housing field with the value “Residência Estudantil” and I need to only display the records that has meal with “Café da Manhã” AND housing with “Residência Estudantil” at the same object in the array.

I’m sorry I’m could not explain that perfect what I’m trying to do, hope it makes sense.

If someone could help me out, would appreciate a lot.
Thanks

2 Likes

Hi Guys, I’m still with this problem. I was already asked in the Algolia Forum but didn’t get any response either. Is it possible to do this that I’m trying or not?

I saw a suggestion to transform each of this accommodation option as a separate record and use the distinct option, but as I have many options of accommodations it would ending up with a lot of records, and I would like to avoid this.

So I would really appreciate if anyone could help me out.

Thanks

Has anyone figured this out in the 2 years since this post? This is the same scenario I am currently trying to solve for.

Can you share some details on your case Adam?

If I understand the first post correctly, this will require to create a separate record for each accomodation.

[
	{
		"objectID": "999-1",
		"id": 999,
		"country": "Estados Unidos",
		"city": "Fort Lauderdale",
		"programType": "Curso de Idioma",
		"language": "Inglês",
		"courseLoad": "30 Aulas Semanais",
		"hour": "Integral",
		"title": "Intensive English",
		"accommodation": {
			"id": 905,
			"provider": "Homestay",
			"name": "Homestay",
			"housing": "Casa de Família",
			"roomType": "Individual",
			"meal": "Café da Manhã ",
			"bathroom": "Externo Compartilhado",
		},
	},
	{
		"objectID": "999-2",
		"id": 999,
		"country": "Estados Unidos",
		"city": "Fort Lauderdale",
		"programType": "Curso de Idioma",
		"language": "Inglês",
		"courseLoad": "30 Aulas Semanais",
		"hour": "Integral",
		"title": "Intensive English",
		"accommodation": {
			"id": 906,
			"provider": "Homestay",
			"name": "Homestay",
			"housing": "Casa de Família",
			"roomType": "Duplo",
			"meal": "Café da Manhã ",
			"bathroom": "Externo Compartilhado",
		}
	}
]

Thanks Julien, that is how I ended up approaching it in the end. Is this the best/only way to go about this? I’m imagining a scenario where I have 2 or more such properties, and the number of Algolia records per unique entity begins to compound.

1 Like

Yes, it’s the only way. This design is also one of the reason Algolia is so fast but I understand that this can create many records in the end. :slight_smile:

hello
in the above example there is only 1 field which is an array. if there are multiple fields which are array of objects
say field 1 (n elements)
field 2 (m elements)
does that mean n*m records need to be created to overcome this