This is an Indexing pipeline step

If your data contains arrays, you might find yourself wanting to isolate an item from the array and use it in another field for search or UI purposes.

For example, you might have an array of images, but you only want to use the first image in your search UI. To isolate the first image we can do the following in the indexing pipeline.

First navigate to Indexing > Advanced. We are going to place the following code into the file:

- id: string-eval
      constant: IF(LENGTH(fields.images) > 0,fields.images[0],"")
      constant: image

This is what the above does:

  1. Looks for a field called images (this is our images array) and checks if it has more than 1 image in the array.

  2. If it does have more than one image, it grabs the first image with the array index of 0.

  3. This first image is then written to a schema field called image. You can name this to whatever you want, just make sure you have added a new schema field with your chosen name in the schema area of the console.

That’s it. Job done 🥳 .

Now you have an isolated image for use in your search UI. You can apply the same logic above to any array in your data set.