use of org.springframework.data.elasticsearch.core.query.CriteriaQuery 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.query.CriteriaQuery in project spring-data-elasticsearch by spring-projects.
the class ReactiveElasticsearchTemplateUnitTests method searchShouldApplyIndexOptionsIfSet.
// DATAES-504, DATAES-518
@Test
public void searchShouldApplyIndexOptionsIfSet() {
ArgumentCaptor<SearchRequest> captor = ArgumentCaptor.forClass(SearchRequest.class);
when(client.search(captor.capture())).thenReturn(Flux.empty());
template.setIndicesOptions(IndicesOptions.LENIENT_EXPAND_OPEN);
Query query = new CriteriaQuery(new Criteria("*")).setPageable(PageRequest.of(0, 10));
//
template.search(query, SampleEntity.class, index).as(//
StepVerifier::create).verifyComplete();
assertThat(captor.getValue().indicesOptions()).isEqualTo(IndicesOptions.LENIENT_EXPAND_OPEN);
}
use of org.springframework.data.elasticsearch.core.query.CriteriaQuery in project spring-data-elasticsearch by spring-projects.
the class ReactiveElasticsearchTemplateUnitTests method searchShouldFallBackToDefaultIndexOptionsIfNotSet.
// DATAES-504, DATAES-518
@Test
public void searchShouldFallBackToDefaultIndexOptionsIfNotSet() {
ArgumentCaptor<SearchRequest> captor = ArgumentCaptor.forClass(SearchRequest.class);
when(client.search(captor.capture())).thenReturn(Flux.empty());
//
template.search(new CriteriaQuery(new Criteria("*")).setPageable(PageRequest.of(0, 10)), SampleEntity.class).as(//
StepVerifier::create).verifyComplete();
assertThat(captor.getValue().indicesOptions()).isEqualTo(DEFAULT_INDICES_OPTIONS);
}
use of org.springframework.data.elasticsearch.core.query.CriteriaQuery in project spring-data-elasticsearch by spring-projects.
the class ReactiveElasticsearchTemplateUnitTests method searchShouldApplyPaginationIfSet.
// DATAES-504
@Test
public void searchShouldApplyPaginationIfSet() {
ArgumentCaptor<SearchRequest> captor = ArgumentCaptor.forClass(SearchRequest.class);
when(client.search(captor.capture())).thenReturn(Flux.empty());
Query query = new CriteriaQuery(new Criteria("*")).setPageable(PageRequest.of(2, 50));
//
template.search(query, SampleEntity.class, index).as(//
StepVerifier::create).verifyComplete();
assertThat(captor.getValue().source().from()).isEqualTo(100);
assertThat(captor.getValue().source().size()).isEqualTo(50);
}
use of org.springframework.data.elasticsearch.core.query.CriteriaQuery in project spring-data-elasticsearch by spring-projects.
the class ReactiveElasticsearchTemplateUnitTests method searchShouldUseScrollIfPaginationNotSet.
// DATAES-504, DATAES-518
@Test
public void searchShouldUseScrollIfPaginationNotSet() {
ArgumentCaptor<SearchRequest> captor = ArgumentCaptor.forClass(SearchRequest.class);
when(client.scroll(captor.capture())).thenReturn(Flux.empty());
//
template.search(new CriteriaQuery(new Criteria("*")).setPageable(Pageable.unpaged()), SampleEntity.class).as(//
StepVerifier::create).verifyComplete();
verify(client).scroll(any());
}
Aggregations