Search in sources :

Example 1 with StringQuery

use of org.springframework.data.elasticsearch.core.query.StringQuery in project spring-data-elasticsearch by spring-projects.

the class ReactiveElasticsearchStringQueryUnitTests method bindsExpressionPropertyCorrectly.

// DATAES-519
@Test
@Disabled("TODO: fix spel query integration")
public void bindsExpressionPropertyCorrectly() throws Exception {
    ReactiveElasticsearchStringQuery elasticsearchStringQuery = createQueryForMethod("findByNameWithExpression", String.class);
    StubParameterAccessor accessor = new StubParameterAccessor("Luke");
    org.springframework.data.elasticsearch.core.query.Query query = elasticsearchStringQuery.createQuery(accessor);
    StringQuery reference = new StringQuery("{ 'bool' : { 'must' : { 'term' : { 'name' : 'Luke' } } } }");
    assertThat(query).isInstanceOf(StringQuery.class);
    assertThat(((StringQuery) query).getSource()).isEqualTo(reference.getSource());
}
Also used : StringQuery(org.springframework.data.elasticsearch.core.query.StringQuery) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 2 with StringQuery

use of org.springframework.data.elasticsearch.core.query.StringQuery in project spring-data-elasticsearch by spring-projects.

the class ReactiveElasticsearchTemplateUnitTests method deleteByShouldUseDefaultRefreshPolicy.

// DATAES-504
@Test
public void deleteByShouldUseDefaultRefreshPolicy() {
    ArgumentCaptor<DeleteByQueryRequest> captor = ArgumentCaptor.forClass(DeleteByQueryRequest.class);
    when(client.deleteBy(captor.capture())).thenReturn(Mono.empty());
    // 
    template.delete(new StringQuery(QueryBuilders.matchAllQuery().toString()), Object.class, index).as(// 
    StepVerifier::create).verifyComplete();
    assertThat(captor.getValue().isRefresh()).isTrue();
}
Also used : DeleteByQueryRequest(org.elasticsearch.index.reindex.DeleteByQueryRequest) StringQuery(org.springframework.data.elasticsearch.core.query.StringQuery) Test(org.junit.jupiter.api.Test)

Example 3 with StringQuery

use of org.springframework.data.elasticsearch.core.query.StringQuery in project spring-data-elasticsearch by spring-projects.

the class ReactiveElasticsearchTemplateUnitTests method deleteByShouldApplyIndicesOptions.

// DATAES-504
@Test
public void deleteByShouldApplyIndicesOptions() {
    ArgumentCaptor<DeleteByQueryRequest> captor = ArgumentCaptor.forClass(DeleteByQueryRequest.class);
    when(client.deleteBy(captor.capture())).thenReturn(Mono.empty());
    // 
    template.delete(new StringQuery(QueryBuilders.matchAllQuery().toString()), Object.class, index).as(// 
    StepVerifier::create).verifyComplete();
    assertThat(captor.getValue().indicesOptions()).isEqualTo(DEFAULT_INDICES_OPTIONS);
}
Also used : DeleteByQueryRequest(org.elasticsearch.index.reindex.DeleteByQueryRequest) StringQuery(org.springframework.data.elasticsearch.core.query.StringQuery) Test(org.junit.jupiter.api.Test)

Example 4 with StringQuery

use of org.springframework.data.elasticsearch.core.query.StringQuery in project spring-data-elasticsearch by spring-projects.

the class ReactiveElasticsearchTemplateUnitTests method deleteByShouldApplyIndicesOptionsIfSet.

// DATAES-504
@Test
public void deleteByShouldApplyIndicesOptionsIfSet() {
    ArgumentCaptor<DeleteByQueryRequest> captor = ArgumentCaptor.forClass(DeleteByQueryRequest.class);
    when(client.deleteBy(captor.capture())).thenReturn(Mono.empty());
    template.setIndicesOptions(IndicesOptions.LENIENT_EXPAND_OPEN);
    // 
    template.delete(new StringQuery(QueryBuilders.matchAllQuery().toString()), Object.class, index).as(// 
    StepVerifier::create).verifyComplete();
    assertThat(captor.getValue().indicesOptions()).isEqualTo(IndicesOptions.LENIENT_EXPAND_OPEN);
}
Also used : DeleteByQueryRequest(org.elasticsearch.index.reindex.DeleteByQueryRequest) StringQuery(org.springframework.data.elasticsearch.core.query.StringQuery) Test(org.junit.jupiter.api.Test)

Example 5 with StringQuery

use of org.springframework.data.elasticsearch.core.query.StringQuery in project spring-data-elasticsearch by spring-projects.

the class ReactiveElasticsearchTemplateUnitTests method deleteByShouldApplyRefreshPolicy.

// DATAES-504
@Test
public void deleteByShouldApplyRefreshPolicy() {
    ArgumentCaptor<DeleteByQueryRequest> captor = ArgumentCaptor.forClass(DeleteByQueryRequest.class);
    when(client.deleteBy(captor.capture())).thenReturn(Mono.empty());
    template.setRefreshPolicy(RefreshPolicy.NONE);
    // 
    template.delete(new StringQuery(QueryBuilders.matchAllQuery().toString()), Object.class, index).as(// 
    StepVerifier::create).verifyComplete();
    assertThat(captor.getValue().isRefresh()).isFalse();
}
Also used : DeleteByQueryRequest(org.elasticsearch.index.reindex.DeleteByQueryRequest) StringQuery(org.springframework.data.elasticsearch.core.query.StringQuery) Test(org.junit.jupiter.api.Test)

Aggregations

StringQuery (org.springframework.data.elasticsearch.core.query.StringQuery)8 Test (org.junit.jupiter.api.Test)7 DeleteByQueryRequest (org.elasticsearch.index.reindex.DeleteByQueryRequest)4 IndexCoordinates (org.springframework.data.elasticsearch.core.mapping.IndexCoordinates)2 Disabled (org.junit.jupiter.api.Disabled)1 SearchHits (org.springframework.data.elasticsearch.core.SearchHits)1 Query (org.springframework.data.elasticsearch.core.query.Query)1 SpringIntegrationTest (org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)1 ParametersParameterAccessor (org.springframework.data.repository.query.ParametersParameterAccessor)1