I have a jsonb structure which contains an array of elements. Those elements have an ‘idElem’, ‘typeElem’ and ‘deleteDate’. I wish to get the whole row if the id and the type match a certain value and if the delete date is null. What we had until today worked fine but we have stumbled upon a case where our query doesn’t return what we expected.
Our query so far looks like this (obviously the value in the matching conditions are for the sake of this post) :
We have a case where two elements of this array have the same id and the same type but one has a delete date and the other doesn’t. What I expected is to have the row returned because one of the elements satisfied the conditions but it turn sout I don’t have any result.
Could someone explain to me why is this the case ? And how should I change the query to have the expected result ?
have you used the nested structure when mapping the elements? (see Hibernate Search 7.2.3.Final: Reference Documentation) If not, and you’ve used the flattened structure, you’ll essentially end up with an array combining all the values from elements, so if one of those had a delete date it ends up as if all of them had for that document.
Otherwise, the query seems fine at first glance.
So with this structure, the query should perform as I expected, that’s right ? Can you perhaps explain me how I can debug in a better way how the query is being processed ? Or at least see the final query ?
Actually, at first we used the bool query but then I tried switching to the and/or/not because it felt more intuitive for our use case (pure personal opinion).
I just tried with your example (and also with the or/and/not for those that want to know) and it works now. It seems that the “.nested(…)” is mandatory.
Our team is still new to Hibernate Search and apparently we didn’t understand how the nested structure worked. After re-reading the documentation I assume that if you don’t use the “.nested(…)” in your query, it actually don’t use the index as a tree ? Or does it act as if we actually used the flattened structure ? If you have answers to those questions, I’d be glad to know.
I’ll do some more tests tomorrow to see if everything is solved and if that’s the case I’ll mark your answer as a solution.