I am using spring data's elastic search module, but I am having troubles building a query. It is a very easy query though. My document looks as follows:
@Document(indexName = "triber-sensor", type = "event")
public class EventDocument implements Event {
@Id
private String id;
@Field(type = FieldType.String)
private EventMode eventMode;
@Field(type = FieldType.String)
private EventSubject eventSubject;
@Field(type = FieldType.String)
private String eventId;
@Field(type = FieldType.Date)
private Date creationDate;
}
And the spring data repository looks like:
public interface EventJpaRepository extends ElasticsearchRepository<EventDocument, String> {
List<EventDocument> findAllOrderByCreationDateDesc(Pageable pageable);
}
So I am trying to get all events ordered by creationDate with the newest event first. However when I run the code I get an exception (also in STS):
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property desc found for type Date! Traversed path: EventDocument.creationDate.
So it seems that it is not picking up the 'OrderBy' part? However a query with a findBy clause (eg findByCreationDateOrderByCreationDateDesc) seems to be okay. Also a findAll without ordering works. Does this mean that the elastic search module of spring data doesn't allow findAll with ordering?
Page<EventDocument> findAll = eventJpaRepository.findAll(new PageRequest(pageable.getPageNumber(), pageable.getPageSize(), new Sort(Direction.DESC, "creationDate"))); return findAll.getContent()
. But i find it very ugly – Geert Olaerts