wanted to know the alternative for that .
Ps: I had almost 200 test cases in HS5 code and now after all the migration even single Testcase is not succeeding and every time got null result.
That’s exactly what will happen when you use @GenericField.
I’d advise you to read the getting started guide first. This section in particular explains how to define analyzers in Hibernate Search 6, and how to assign them to fields.
Essentially:
Define analyzers by implementing LuceneAnalysisConfigurer and then setting the configuration property hibernate.search.backend.analysis.configurer to the fully-qualified name of your implementation class (e.g. com.mycompany.config.MyAnalysisConfigurer).
Assign analyzers to field by mapping them using @FullTextField (instead of @GenericField) and then setting @FullTextField(analyzer = "emailNgram").
Range queries will work out of the box without the need to use a string encoding type.
So essentially you should map the date like this:
@GenericField
private Date creationDate;
And then query like this:
Date before = ...;
Date after = ...;
List<MyEntity> hits = Search.session(session).search(MyEntity.class)
.where(f -> f.range().field("creationDate").between(before, after))
.fetchHits(20);
So if I query like “ticketId” it is giving result (Class to query here is Ticket)
However if I query like “tickets.ticketId” its returning null (Class to query here is SaleSaga)
Ok, that’s clearer, but what is null exactly? What is the code you use to generate your query? (.search(SaleSaga.class).select(...).where( ...).fetchHits(...))
Something in your predicates isn’t matching. Without knowledge of your predicates and your data, I can’t tell you what is not matching.
One way you could debug this is by commenting out most conditions, then uncommenting them one by one, until you get no results. Then have a look at the last you uncommented, that’s probably the one that doesn’t work.
Ah, and one more thing… when you update associations, you must update both sides. If for example you didn’t add the ticket to SaleSaga.tickets when it was created, then Hibernate Search will not be able to know that this ticket must be indexed-embedded inside this SaleSaga; it won’t be, and you won’t get any match.
here is the query string when its not working
ElasticsearchSearchQueryImpl[{“query”:{“bool”:{“must”:{“match”:{“tickets.ticketId”:{“query”:“77ef74ce-2a66-4fbb-a5f2-3d965c4e0a0b”}}},“minimum_should_match”:“0”}},"_source":false}]
The owning side of your association is Ticket.saleSaga, and you didn’t set that property before saving your ticket. In that case, the association was not persisted, and the result you’re getting reflects the content of the database. Like I said, you must set both sides of your associations. The problem is in how you saved your entity, and everything works well on the Hibernate Search side. Note that you most likely would have the same problem with Hibernate Search 5, since the problem is in how you used Hibernate ORM, not Hibernate Search.
You’re accessing SaleSaga.tickets outside of your transaction or after you closed the session. That’s dodgy and certainly will never work correctly. You should use the DTO pattern to copy data to an object that’s no linked to the session before you transfer it to other components of your application (REST service, …).