Search in sources :

Example 21 with IndexQuery

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

the class ElasticsearchOperationsCallbackIntegrationTests method shouldApplyConversionResultToIndexQueryInBulkIndex.

// DATAES-972
@Test
@DisplayName("should apply conversion result to IndexQuery in bulkIndex")
void shouldApplyConversionResultToIndexQueryInBulkIndex() {
    SampleEntity entity = new SampleEntity("1", "test");
    final IndexQuery indexQuery = new IndexQuery();
    indexQuery.setId(entity.getId());
    indexQuery.setObject(entity);
    operations.bulkIndex(Collections.singletonList(indexQuery), SampleEntity.class);
    ArgumentCaptor<List<IndexQuery>> indexQueryListCaptor = ArgumentCaptor.forClass(List.class);
    verify(operations, times(1)).bulkOperation(indexQueryListCaptor.capture(), any(), any());
    final List<IndexQuery> capturedIndexQueries = indexQueryListCaptor.getValue();
    assertThat(capturedIndexQueries).hasSize(1);
    final IndexQuery capturedIndexQuery = capturedIndexQueries.get(0);
    SampleEntity convertedEntity = (SampleEntity) capturedIndexQuery.getObject();
    final JoinField<String> joinField = convertedEntity.getJoinField();
    assertThat(joinField.getName()).isEqualTo("answer");
    assertThat(joinField.getParent()).isEqualTo("42");
    assertThat(capturedIndexQuery.getRouting()).isEqualTo("42");
    assertThat(capturedIndexQuery.getSeqNo()).isEqualTo(seqNoPrimaryTerm.getSequenceNumber());
    assertThat(capturedIndexQuery.getPrimaryTerm()).isEqualTo(seqNoPrimaryTerm.getPrimaryTerm());
}
Also used : IndexQuery(org.springframework.data.elasticsearch.core.query.IndexQuery) List(java.util.List) Test(org.junit.jupiter.api.Test) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 22 with IndexQuery

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

the class ElasticsearchOperationsCallbackIntegrationTests method shouldApplyConversionResultToIndexQueryWhenNotSet.

// DATAES-972
@Test
@DisplayName("should apply conversion result to IndexQuery when not set ")
void shouldApplyConversionResultToIndexQueryWhenNotSet() {
    SampleEntity entity = new SampleEntity("1", "test");
    final IndexQuery indexQuery = new IndexQuery();
    indexQuery.setId(entity.getId());
    indexQuery.setObject(entity);
    operations.index(indexQuery, IndexCoordinates.of(INDEX));
    ArgumentCaptor<IndexQuery> indexQueryCaptor = ArgumentCaptor.forClass(IndexQuery.class);
    verify(operations, times(2)).doIndex(indexQueryCaptor.capture(), any());
    final IndexQuery capturedIndexQuery = indexQueryCaptor.getValue();
    SampleEntity convertedEntity = (SampleEntity) capturedIndexQuery.getObject();
    final JoinField<String> joinField = convertedEntity.getJoinField();
    assertThat(joinField.getName()).isEqualTo("answer");
    assertThat(joinField.getParent()).isEqualTo("42");
    assertThat(capturedIndexQuery.getRouting()).isEqualTo("42");
    assertThat(capturedIndexQuery.getSeqNo()).isEqualTo(seqNoPrimaryTerm.getSequenceNumber());
    assertThat(capturedIndexQuery.getPrimaryTerm()).isEqualTo(seqNoPrimaryTerm.getPrimaryTerm());
}
Also used : IndexQuery(org.springframework.data.elasticsearch.core.query.IndexQuery) Test(org.junit.jupiter.api.Test) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 23 with IndexQuery

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

the class GeoIntegrationTests method buildIndex.

private IndexQuery buildIndex(LocationMarkerEntity result) {
    IndexQuery indexQuery = new IndexQuery();
    indexQuery.setId(result.getId());
    indexQuery.setObject(result);
    return indexQuery;
}
Also used : IndexQuery(org.springframework.data.elasticsearch.core.query.IndexQuery)

Example 24 with IndexQuery

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

the class ElasticsearchOperationsCallbackIntegrationTests method shouldNotApplyConversionResultToIndexQueryWhenAlreadySet.

// DATAES-972
@Test
@DisplayName("should not apply conversion result to IndexQuery when already set ")
void shouldNotApplyConversionResultToIndexQueryWhenAlreadySet() {
    SeqNoPrimaryTerm seqNoPrimaryTermOriginal = seqNoPrimaryTerm;
    seqNoPrimaryTerm = new SeqNoPrimaryTerm(7, 8);
    SampleEntity entity = new SampleEntity("1", "test");
    final IndexQuery indexQuery = new IndexQuery();
    indexQuery.setId(entity.getId());
    indexQuery.setObject(entity);
    indexQuery.setRouting("12");
    indexQuery.setSeqNo(seqNoPrimaryTermOriginal.getSequenceNumber());
    indexQuery.setPrimaryTerm(seqNoPrimaryTermOriginal.getPrimaryTerm());
    operations.index(indexQuery, IndexCoordinates.of(INDEX));
    ArgumentCaptor<IndexQuery> indexQueryCaptor = ArgumentCaptor.forClass(IndexQuery.class);
    verify(operations, times(2)).doIndex(indexQueryCaptor.capture(), any());
    final IndexQuery capturedIndexQuery = indexQueryCaptor.getValue();
    SampleEntity convertedEntity = (SampleEntity) capturedIndexQuery.getObject();
    final JoinField<String> joinField = convertedEntity.getJoinField();
    assertThat(joinField.getName()).isEqualTo("answer");
    assertThat(joinField.getParent()).isEqualTo("42");
    assertThat(capturedIndexQuery.getRouting()).isEqualTo("12");
    assertThat(capturedIndexQuery.getSeqNo()).isEqualTo(seqNoPrimaryTermOriginal.getSequenceNumber());
    assertThat(capturedIndexQuery.getPrimaryTerm()).isEqualTo(seqNoPrimaryTermOriginal.getPrimaryTerm());
}
Also used : IndexQuery(org.springframework.data.elasticsearch.core.query.IndexQuery) SeqNoPrimaryTerm(org.springframework.data.elasticsearch.core.query.SeqNoPrimaryTerm) Test(org.junit.jupiter.api.Test) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 25 with IndexQuery

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

the class NestedObjectTests method shouldIndexInitialLevelNestedObject.

@Test
public void shouldIndexInitialLevelNestedObject() {
    List<Car> cars = new ArrayList<>();
    Car saturn = new Car();
    saturn.setName("Saturn");
    saturn.setModel("SL");
    Car subaru = new Car();
    subaru.setName("Subaru");
    subaru.setModel("Imprezza");
    Car ford = new Car();
    ford.setName("Ford");
    ford.setModel("Focus");
    cars.add(saturn);
    cars.add(subaru);
    cars.add(ford);
    Person foo = new Person();
    foo.setName("Foo");
    foo.setId("1");
    foo.setCar(cars);
    Car car = new Car();
    car.setName("Saturn");
    car.setModel("Imprezza");
    Person bar = new Person();
    bar.setId("2");
    bar.setName("Bar");
    bar.setCar(Collections.singletonList(car));
    List<IndexQuery> indexQueries = new ArrayList<>();
    IndexQuery indexQuery1 = new IndexQuery();
    indexQuery1.setId(foo.getId());
    indexQuery1.setObject(foo);
    IndexQuery indexQuery2 = new IndexQuery();
    indexQuery2.setId(bar.getId());
    indexQuery2.setObject(bar);
    indexQueries.add(indexQuery1);
    indexQueries.add(indexQuery2);
    IndexCoordinates index = IndexCoordinates.of("test-index-person");
    operations.bulkIndex(indexQueries, index);
    operations.indexOps(Person.class).refresh();
    QueryBuilder builder = nestedQuery("car", boolQuery().must(termQuery("car.name", "saturn")).must(termQuery("car.model", "imprezza")), ScoreMode.None);
    Query searchQuery = new NativeSearchQueryBuilder().withQuery(builder).build();
    SearchHits<Person> persons = operations.search(searchQuery, Person.class, index);
    assertThat(persons).hasSize(1);
}
Also used : IndexQuery(org.springframework.data.elasticsearch.core.query.IndexQuery) Query(org.springframework.data.elasticsearch.core.query.Query) IndexQuery(org.springframework.data.elasticsearch.core.query.IndexQuery) NativeSearchQuery(org.springframework.data.elasticsearch.core.query.NativeSearchQuery) ArrayList(java.util.ArrayList) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) NativeSearchQueryBuilder(org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) NativeSearchQueryBuilder(org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder) IndexCoordinates(org.springframework.data.elasticsearch.core.mapping.IndexCoordinates) Test(org.junit.jupiter.api.Test) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)

Aggregations

IndexQuery (org.springframework.data.elasticsearch.core.query.IndexQuery)31 Test (org.junit.jupiter.api.Test)12 SpringIntegrationTest (org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)9 ArrayList (java.util.ArrayList)8 IndexCoordinates (org.springframework.data.elasticsearch.core.mapping.IndexCoordinates)8 DisplayName (org.junit.jupiter.api.DisplayName)4 IndexQueryBuilder (org.springframework.data.elasticsearch.core.query.IndexQueryBuilder)4 NativeSearchQuery (org.springframework.data.elasticsearch.core.query.NativeSearchQuery)4 NativeSearchQueryBuilder (org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder)4 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)3 HashMap (java.util.HashMap)2 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 SeqNoPrimaryTerm (org.springframework.data.elasticsearch.core.query.SeqNoPrimaryTerm)2 Commodity (com.example.esdemo.dto.Commodity)1 CommonException (com.huaxing.springboot_elasticsearch.common.utils.CommonException)1 UserEntity (com.javayh.elaticsearh.docment.UserEntity)1 Field (java.lang.reflect.Field)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Collection (java.util.Collection)1