0
votes

I am trying to search HazelcastJsonValue, data example for the same.

class A {
 B[] listOfB;
}

class B {
 int num;
 String name;
}

'A' object is present in Hazelcast as HazelcastJsonValue and i want to create query which fetches all objects which contain B for which num = 10 and name = test hazelcast query for array search using predicate

Predicate.equal("listOfB[any].name","test")

for above scenario query i can make using predicates

Predicate[] arrayOfPredicate = {Predicates.equal("listOfB[any].num",10)
                ,Predicates.equal("listOfB[any].name","test")};
Predicate p = Predicates.and(arrayOfPredicate);
System.out.println(p.toString()); // (listOfB[any].num=10 AND listOfB[any].name=test)

Example Data in hazelcast

[
  {
    "listOfB": [
      {
        "num": 10,
        "name": "ab"
      },
      {
        "num": 11,
        "name": "test"
      }
    ]
  },
  {
    "listOfB": [
      {
        "num": 10,
        "name": "test"
      },
      {
        "num": 12,
        "name": "xyz"
      }
    ]
  },
{
    "listOfB": [
      {
        "num": 30,
        "name": "abc"
      }
    ]
  }
]

Hazelcast query for same

(listOfB[any].num=10 AND listOfB[any].name=test) But this is not giving desired results instead below result came

[
  {
    "listOfB": [
      {
        "num": 10,
        "name": "ab"
      },
      {
        "num": 11,
        "name": "test"
      }
    ]
  },
  {
    "listOfB": [
      {
        "num": 10,
        "name": "test"
      },
      {
        "num": 12,
        "name": "xyz"
      }
    ]
  }
]

Desired results are

{
  "listOfB": [
    {
      "num": 10,
      "name": "test"
    },
    {
      "num": 12,
      "name": "xyz"
    }
  ]
}

How can i get desired results?

1

1 Answers

0
votes

Both of the above should've been returned in your result set. Is this not the case? The fact that you're wanting any will return true for the above data. If you limited the filter to listOfB[0], then the 2nd will be returned but I'm sure your intention is to not limit to 1st item only.