How to create Index of json array with only values?

I have a field called storeImageNameList which stores image names,
Now if i want to get value by image name then how to create index on json array,
Eg: storeImageNameList :[“image1”,“image2”,“image3”…]

Below is the Document values image,

I want to fetch Bridge001 from document what can be done?

CREATE INDEX ix1 ON default(DISTINCT ARRAY c FOR c IN usedcarimages END) 
WHERE _class = "com.usedCars.ServiceUsedCars.pojo.UsedCarDetails";

SELECT d.* 
FROM default AS d
WHERE  d._class = "com.usedCars.ServiceUsedCars.pojo.UsedCarDetails"
                     AND ANY c IN d.usedcarimages SATISFIES c = "Bridge001" END;

Last Image name in the array

SELECT d.usedcarimages[-1] AS lastimage
FROM default AS d
WHERE  d._class = "com.usedCars.ServiceUsedCars.pojo.UsedCarDetails"
                     AND ANY c IN d.usedcarimages SATISFIES c = "Bridge001" END;

If you want sort and get last image

SELECT ARRAY_SORT(d.usedcarimages)[-1] AS lastimage
FROM default AS d
WHERE  d._class = "com.usedCars.ServiceUsedCars.pojo.UsedCarDetails"
                     AND ANY c IN d.usedcarimages SATISFIES c = "Bridge001" END;
1 Like

did not fetch the result…

You might not have matching record. Post actual document you expecting

thank you very much got the records

if image names are stored in following way,

Bridge01-1
Bridge01-2
Bridge01-3

then how can i get all the names by just giving input Bridge01 and not mentioning full name like Bridge01-1?

SELECT * FROM UsedCar
WHERE ANY v IN usedcarimages SATISFIES v LIKE ‘%Bridge01%’ END;

If you need string started with Bridge01 don’t give leading %. It will impact performance.

SELECT * FROM UsedCar
WHERE ANY v IN usedcarimages SATISFIES v LIKE "Bridge01%" END;