Filter if attribute exists

Hello guys,

I use react instant search and my data elements look like this:

{
id: string // required
date1: (timestamp) // optionnal
date2: (timestamp) // optionnal
description.name: (string) // optionnal
description.lastname: (string) // required
}

I was wondering if I can use a toogle widget to display all elements that contains a specific argument.
For exemple I would have 2 toggles: “date1” and “name”:

  • If I toggle date1 I want to get all the elements that contain a date1
  • If I toggle name I want to get all the elements that contain a description.name
  • If I toggle both of them I want to get all elements that contain a date1 and a description.name

I tried something like this:

<Toggle
	attributeName="date1"
	label="Date1"
	value={"*"}
/>

But it seams that we cant get all elements using a “*” wildcard.

Any idea ?

Hi Vincent,

Algolia doesn’t support filtering on null (or not-null) values so you can’t use the Toggle widget to do that (see this post). But you can manage that case by adding 2 extra attributes:

  • hasDate1 (true/false)
  • hasDescriptionName (true/false)

You can then use the Toggle widget to filter on these 2 attributes.

Let us know it that worked for you!

Hi Karim,

Thank you for the answer, I added an extra attribute to my data and it works well :slight_smile:

Great to here that! :slight_smile:

1 Like