List of usage examples for org.springframework.data.domain Sort.Order Sort.Order
public Order(@Nullable Direction direction, String property)
From source file:com.github.vanroy.springdata.jest.JestElasticsearchTemplateTests.java
@Test @Ignore("By default, the search request will fail if there is no mapping associated with a field. The ignore_unmapped option allows to ignore fields that have no mapping and not sort by them") public void shouldReturnSortedPageableResultsGivenStringQuery() { // given/*from w w w.ja va2 s. c om*/ String documentId = randomNumeric(5); SampleEntity sampleEntity = new SampleEntity(); sampleEntity.setId(documentId); sampleEntity.setMessage("some message"); sampleEntity.setVersion(System.currentTimeMillis()); IndexQuery indexQuery = new IndexQuery(); indexQuery.setId(documentId); indexQuery.setObject(sampleEntity); elasticsearchTemplate.index(indexQuery); elasticsearchTemplate.refresh(SampleEntity.class); StringQuery stringQuery = new StringQuery(matchAllQuery().toString(), new PageRequest(0, 10), new Sort(new Sort.Order(Sort.Direction.ASC, "messsage"))); // when Page<SampleEntity> sampleEntities = elasticsearchTemplate.queryForPage(stringQuery, SampleEntity.class); // then assertThat(sampleEntities.getTotalElements(), is(greaterThanOrEqualTo(1L))); }