'Query to search value in side array of object

I want to apply criteria inside object of array if it matches, but I am not able to find any documentation or example where I can find that using spring-data-cosmosdb library. I am using 2.3.0 version of library.

Example of Json

{
  "id" : 1,
  "address" : [
    {
     "street" : "abc" 
     ...         
    },
    {
     "street" : "efg" 
     ...
    }
  ]
}

I wan to search all documents in which address is having street name equals "abc". Below is spring boot code that I am using to search in cosmosDb. But it is not returning expected results.

    List<Criteria> criteriaList = new ArrayList<>();
    criteriaList.add(Criteria.getInstance(CriteriaType.IN, "addresses.street", Collections.singletonList("abc")));
    List<User> users = cosmosTemplate.find(new DocumentQuery(criteriaList.get(0), CriteriaType.AND)), User.class, COLLECTION_NAME);

I also tried with address[0].street, but it is throwing exception of operation not supported.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source