I have an entity with indexed creation timestamp of java.time.Instant
type and I'd like to facet search results by creation timestamp range.
The entity looks the following way:
@Entity
@Indexed
public class Document {
@Id
@DocumentId
private Long id;
@Field
private String name;
@Field(analyze = Analyze.NO)
@Facet
private Instant creationTimestamp;
}
When I start my application I get the following error:
org.hibernate.search.exception.SearchException: HSEARCH000264: @Facet is not supported for type 'java.time.Instant'. See org.hibernate.search.bugs.Document#creationTimestamp
I haven't found anything related to faceting by Instant value in hibernate documentation .
Is it possible to facet hibernate search results by creation timestamp range?
I've created a failing test case here: github repo link
I'm afraid Java 8 date/time types are not yet supported in the Hibernate Search faceting subsystem. I created an ticket to address this, but I can't say when we will (there are internal complications): https://hibernate.atlassian.net/browse/HSEARCH-2954
UPDATE : Facets on date/time types are supported in Hibernate Search 6 with aggregations, which replace Hibernate Search 5 facets. Getting started with Hibernate Search 6 , Aggregations in Hibernate Search 6 .
In the meantime, you can work around this lack of support by using a @Transient
long field representing the timestamp:
@Entity
@Indexed
public class Document {
@Id
@DocumentId
private Long id;
@Field
private String name;
private Instant creationTimestamp;
@Field(analyze = Analyze.NO)
@Facet
@javax.persistence.Transient
public Long getCreationForFaceting() {
return creationTimestamp == null ? null : creationTimestamp.toEpochMilli();
}
}
And then querying using long timestamps too.
Not an ideal solution by a long shot, but it's the only one I can think of.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.