use of org.elasticsearch.action.search.SearchRequest in project spring-data-elasticsearch by spring-projects.
the class ReactiveElasticsearchClientUnitTests method searchShouldHitSearchEndpoint.
// --> SEARCH
// DATAES-488
@Test
public void searchShouldHitSearchEndpoint() {
//
hostProvider.when(HOST).receiveSearchOk();
client.search(new SearchRequest("twitter")).as(StepVerifier::create).verifyComplete();
verify(hostProvider.client(HOST)).method(HttpMethod.POST);
URI uri = hostProvider.when(HOST).captureUri();
assertThat(uri.getRawPath()).isEqualTo("/twitter/_search");
}
use of org.elasticsearch.action.search.SearchRequest in project spring-data-elasticsearch by spring-projects.
the class ReactiveElasticsearchClientUnitTests method searchShouldReturnEmptyFluxIfNothingFound.
// DATAES-488
@Test
public void searchShouldReturnEmptyFluxIfNothingFound() {
//
hostProvider.when(HOST).receiveSearchOk();
//
client.search(new SearchRequest("twitter")).as(//
StepVerifier::create).verifyComplete();
}
use of org.elasticsearch.action.search.SearchRequest in project spring-data-elasticsearch by spring-projects.
the class ReactiveElasticsearchClientUnitTests method aggregateShouldReturnMultipleResultsCorrectly.
// DATAES-567
@Test
public void aggregateShouldReturnMultipleResultsCorrectly() {
//
hostProvider.when(HOST).receive(//
Receive::json).body(fromPath("aggregate-ok-multiple-results"));
//
client.aggregate(new SearchRequest("twitter")).as(//
StepVerifier::create).consumeNextWith(aggregation -> {
assertThat(aggregation.getName()).isEqualTo("users");
assertThat(aggregation instanceof ParsedStringTerms);
ParsedStringTerms parsedStringTerms = (ParsedStringTerms) aggregation;
assertThat(parsedStringTerms.getBuckets().size()).isEqualTo(2);
assertThat(parsedStringTerms.getBucketByKey("kimchy").getDocCount()).isEqualTo(2);
assertThat(parsedStringTerms.getBucketByKey("elastic").getDocCount()).isEqualTo(1);
}).consumeNextWith(aggregation -> {
assertThat(aggregation.getName()).isEqualTo("max_post_date");
assertThat(aggregation instanceof ParsedMax);
ParsedMax parsedMax = (ParsedMax) aggregation;
assertThat(Instant.ofEpochMilli((long) parsedMax.getValue())).isEqualTo(Instant.parse("2010-01-15T01:46:38Z"));
}).verifyComplete();
}
use of org.elasticsearch.action.search.SearchRequest in project spring-data-elasticsearch by spring-projects.
the class ReactiveElasticsearchTemplate method doCount.
private Mono<Long> doCount(Query query, Class<?> entityType, IndexCoordinates index) {
return Mono.defer(() -> {
SearchRequest request = requestFactory.searchRequest(query, entityType, index);
request = prepareSearchRequest(request, false);
return doCount(request);
});
}
use of org.elasticsearch.action.search.SearchRequest in project spring-data-elasticsearch by spring-projects.
the class ReactiveElasticsearchTemplate method doFind.
private Flux<SearchDocument> doFind(Query query, Class<?> clazz, IndexCoordinates index) {
return Flux.defer(() -> {
SearchRequest request = requestFactory.searchRequest(query, clazz, index);
boolean useScroll = !(query.getPageable().isPaged() || query.isLimiting());
request = prepareSearchRequest(request, useScroll);
if (useScroll) {
return doScroll(request);
} else {
return doFind(request);
}
});
}
Aggregations