use of org.springframework.data.elasticsearch.core.SearchPage in project spring-data-elasticsearch by spring-projects.
the class SimpleElasticsearchRepository method findAll.
@SuppressWarnings("unchecked")
@Override
public Page<T> findAll(Pageable pageable) {
NativeSearchQuery query = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).withPageable(pageable).build();
SearchHits<T> searchHits = execute(operations -> operations.search(query, entityClass, getIndexCoordinates()));
// noinspection ConstantConditions
SearchPage<T> page = SearchHitSupport.searchPageFor(searchHits, query.getPageable());
return (Page<T>) SearchHitSupport.unwrapSearchHits(page);
}
use of org.springframework.data.elasticsearch.core.SearchPage in project prolog by woowacourse.
the class StudylogDocumentService method findBySearchKeyword.
@Override
public StudylogDocumentResponse findBySearchKeyword(String keyword, List<Long> tags, List<Long> missions, List<Long> levels, List<String> usernames, LocalDate start, LocalDate end, Pageable pageable) {
final Query query = StudylogDocumentQueryBuilder.makeQuery(preprocess(keyword), tags, missions, levels, usernames, start, end, pageable);
// Query 결과를 ES에서 조회한다.
final SearchHits<StudylogDocument> searchHits = elasticsearchRestTemplate.search(query, StudylogDocument.class, IndexCoordinates.of("studylog-document"));
// 조회된 SearchHits를 페이징할 수 있는 SearchPage로 변경한다.
final SearchPage<StudylogDocument> searchPages = SearchHitSupport.searchPageFor(searchHits, query.getPageable());
final List<Long> studylogIds = searchPages.stream().map(searchPage -> searchPage.getContent().getId()).collect(toList());
return StudylogDocumentResponse.of(studylogIds, searchPages.getTotalElements(), searchPages.getTotalPages(), searchPages.getNumber());
}
use of org.springframework.data.elasticsearch.core.SearchPage in project spring-native by spring-projects-experimental.
the class CLR method run.
@Override
public void run(String... args) throws Exception {
{
System.out.println("refresh index");
repository.deleteAll();
operations.indexOps(Conference.class).delete();
operations.indexOps(Conference.class).create();
}
{
System.out.println("\n--- REPOSITORY ---");
// Save data sample
repository.save(Conference.builder().date("2014-11-06").name("Spring eXchange 2014 - London").keywords(Arrays.asList("java", "spring")).location(new GeoPoint(51.500152D, -0.126236D)).build());
repository.save(Conference.builder().date("2014-12-07").name("Scala eXchange 2014 - London").keywords(Arrays.asList("scala", "play", "java")).location(new GeoPoint(51.500152D, -0.126236D)).build());
repository.save(Conference.builder().date("2014-11-20").name("Elasticsearch 2014 - Berlin").keywords(Arrays.asList("java", "elasticsearch", "kibana")).location(new GeoPoint(52.5234051D, 13.4113999)).build());
repository.save(Conference.builder().date("2014-11-12").name("AWS London 2014").keywords(Arrays.asList("cloud", "aws")).location(new GeoPoint(51.500152D, -0.126236D)).build());
repository.save(Conference.builder().date("2014-10-04").name("JDD14 - Cracow").keywords(Arrays.asList("java", "spring")).location(new GeoPoint(50.0646501D, 19.9449799)).build());
System.out.println("repository.count(): " + repository.count());
}
{
System.out.println("\n--- CUSTOM REPOSITORY ---");
SearchPage<Conference> searchPage = repository.findBySomeCustomImplementation("eXchange", PageRequest.of(0, 10));
System.out.println("custom implementation finder.size(): " + searchPage.getSearchHits().getTotalHits());
}
String expectedDate = "2014-10-29";
String expectedWord = "java";
CriteriaQuery query = new CriteriaQuery(new Criteria("keywords").contains(expectedWord).and(new Criteria("date").greaterThanEqual(expectedDate)));
{
System.out.println("\n--- TEMPLATE FIND ---");
SearchHits<Conference> result = operations.search(query, Conference.class, IndexCoordinates.of("conference-index"));
System.out.println("result.size(): " + result.getSearchHits().size());
}
{
System.out.println("\n--- REPOSITORY FINDER ---");
List<Conference> result = repository.findByKeywordsContaining("spring");
System.out.println("result.size(): " + result.size());
}
{
System.out.println("\n--- REACTIVE TEMPLATE ---");
System.out.println("reactiveTemplate.count(): " + reactiveOps.count(Query.findAll(), Conference.class, IndexCoordinates.of("conference-index")).block());
}
{
System.out.println("\n--- REACTIVE REPOSITORY ---");
System.out.println("reactiveRepository.count(): " + reactiveRepository.count().block());
}
{
// does currently not work in SD ES - wrong reactor-netty dependency
// System.out.println("\n--- REACTIVE REPOSITORY FINDER ---");
// System.out.println("result.size(): " + reactiveRepository.findByKeywordsContaining("spring").collectList().block().size());
}
System.out.println("DONE");
}
use of org.springframework.data.elasticsearch.core.SearchPage in project spring-data-elasticsearch by spring-projects.
the class SimpleElasticsearchRepository method searchSimilar.
@SuppressWarnings("unchecked")
@Override
public Page<T> searchSimilar(T entity, @Nullable String[] fields, Pageable pageable) {
Assert.notNull(entity, "Cannot search similar records for 'null'.");
Assert.notNull(pageable, "'pageable' cannot be 'null'");
MoreLikeThisQuery query = new MoreLikeThisQuery();
query.setId(stringIdRepresentation(extractIdFromBean(entity)));
query.setPageable(pageable);
if (fields != null) {
query.addFields(fields);
}
SearchHits<T> searchHits = execute(operations -> operations.search(query, entityClass, getIndexCoordinates()));
SearchPage<T> searchPage = SearchHitSupport.searchPageFor(searchHits, pageable);
return (Page<T>) SearchHitSupport.unwrapSearchHits(searchPage);
}
Aggregations