public class A {
private List<B> bList
}
public class B {
private List<C> bList;
private BigInteger testId;
}
public class C {
private BigInteger type;
}
I would like to get documents where B.testId= {$id} and C.type != {$type} or C.type not exist.
So, i am trying to do something like this
//or not exist c.type
pf.bool().should(pf.bool().mustNot(pf.exists().field("C.type")))
)
// or:
// if B.testId != null and B.testId == {$id} and c.type != {type}
.should(
pf.bool().must(pf.match().field("B.testId").matching(new BigInteger(value)))
.mustNot(pf.match().field("C.type").matching(type))
).toPredicate();
But i cant get the correct result. The problem is that there is a confusion if i have >1 records of class B with different testIds.
I add @IndexedEmbedded(structure = ObjectStructure.NESTED) so my new objects are
public class A {
@IndexedEmbedded(structure = ObjectStructure.NESTED, includePaths = {"testId", "cList.type");
private List<B> bList
}
public class B {
@IndexedEmbedded(structure = ObjectStructure.NESTED, includePaths = {"type");
private List<C> cList;
private BigInteger testId;
}
public class C {
@GenericField(sortable = Sortable.YES)
private BigInteger type;
}
Neither am I, objectField("bList") probably would make more sense here?
Anyway, I can’t really help if all the information you give is “my results are not correct”. If this still doesn’t work, at least give me an example dataset, the result you expect, and the results you’re getting.
i have 2 records on table B (1. with testid = 1 and 2. with testid = 2)
i have 2 records on table C (1. with type = 1 and 2. with type = 2)
Object A contains both objects B and objectB contains both object C
i am on testid = 1, that it already contains the object C with type = 1, and i want to filter the document where type != 1. I am waiting to get 1 record(only type =2 ). so i use,
If so, you’re getting the expected result. Predicates determine which instances of A get returned, they don’t filter out the properties of A. You’ll just get an A with the exact same data that is in the database.
Returning to you a filtered view of A (e.g. in some DTO) that only includes the matching elements in bList/cList would require taking advantage of Elasticsearch’s inner hits, and that’s not currently supported ([HSEARCH-4630] - Hibernate JIRA).
Given that dataset, I wouldn’t expect any hit at all. The first instance of A shouldn’t match because there’s a C with type = 1, and the second instance of A shouldn’t match because the only B has testid = 2.