2015-11-22 47 views
0

我使用彈簧數據的彈性搜索模塊,但我遇到了構建查詢的麻煩。儘管這是一個非常簡單的查詢。 我的文檔看起來如下:彈簧數據彈性搜索findAll with OrderBy

@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; 
} 

和Spring數據倉庫的樣子:

public interface EventJpaRepository extends ElasticsearchRepository<EventDocument, String> { 

    List<EventDocument> findAllOrderByCreationDateDesc(Pageable pageable); 

} 

所以我想獲得通過creationDate與最新事件排序第一的所有事件。然而,當我(也STS)運行代碼我得到一個異常:

Caused by: org.springframework.data.mapping.PropertyReferenceException: No property desc found for type Date! Traversed path: EventDocument.creationDate. 

這樣看來,它不是拿起「排序依據」的一部分?然而,帶有findBy子句的查詢(例如findByCreationDateOrderByCreationDateDesc)似乎沒問題。另外一個findAll沒有訂購作品。 這是否意味着spring數據的彈性搜索模塊不允許findAll與排序?

+0

以下確實工作'頁的findAll = eventJpaRepository.findAll(新PageRequest(pageable.getPageNumber(),pageable.getPageSize (),new Sort(Direction.DESC,「creationDate」))); \t \t return findAll.getContent()'。但我覺得它很醜陋 –

回答

0

嘗試增加通過到方法名稱:
的findAll 通過 OrderByCreationDateDesc