Search in sources :

Example 36 with Document

use of org.springframework.data.elasticsearch.core.document.Document in project spring-data-elasticsearch by spring-projects.

the class ElasticsearchTemplateTests method shouldDoBulkUpdate.

@Test
public void shouldDoBulkUpdate() {
    // given
    String documentId = nextIdAsString();
    String messageBeforeUpdate = "some test message";
    String messageAfterUpdate = "test message";
    SampleEntity sampleEntity = SampleEntity.builder().id(documentId).message(messageBeforeUpdate).version(System.currentTimeMillis()).build();
    IndexQuery indexQuery = getIndexQuery(sampleEntity);
    operations.index(indexQuery, IndexCoordinates.of(indexNameProvider.indexName()));
    org.springframework.data.elasticsearch.core.document.Document document = org.springframework.data.elasticsearch.core.document.Document.create();
    document.put("message", messageAfterUpdate);
    UpdateQuery updateQuery = // 
    UpdateQuery.builder(documentId).withDocument(// 
    document).build();
    List<UpdateQuery> queries = new ArrayList<>();
    queries.add(updateQuery);
    // when
    operations.bulkUpdate(queries, IndexCoordinates.of(indexNameProvider.indexName()));
    // then
    SampleEntity indexedEntity = operations.get(documentId, SampleEntity.class, IndexCoordinates.of(indexNameProvider.indexName()));
    assertThat(indexedEntity.getMessage()).isEqualTo(messageAfterUpdate);
}
Also used : ArrayList(java.util.ArrayList) Document(org.springframework.data.elasticsearch.core.document.Document) Test(org.junit.jupiter.api.Test) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)

Example 37 with Document

use of org.springframework.data.elasticsearch.core.document.Document in project spring-data-elasticsearch by spring-projects.

the class DocumentAdaptersUnitTests method shouldAdaptGetResponse.

// DATAES-628, DATAES-848
@Test
public void shouldAdaptGetResponse() {
    Map<String, DocumentField> fields = Collections.singletonMap("field", new DocumentField("field", Collections.singletonList("value")));
    GetResult getResult = new GetResult("index", "type", "my-id", 1, 2, 42, true, null, fields, null);
    GetResponse response = new GetResponse(getResult);
    Document document = DocumentAdapters.from(response);
    assertThat(document.getIndex()).isEqualTo("index");
    assertThat(document.hasId()).isTrue();
    assertThat(document.getId()).isEqualTo("my-id");
    assertThat(document.hasVersion()).isTrue();
    assertThat(document.getVersion()).isEqualTo(42);
    assertThat(document.get("field")).isEqualTo("value");
    assertThat(document.hasSeqNo()).isTrue();
    assertThat(document.getSeqNo()).isEqualTo(1);
    assertThat(document.hasPrimaryTerm()).isTrue();
    assertThat(document.getPrimaryTerm()).isEqualTo(2);
}
Also used : DocumentField(org.elasticsearch.common.document.DocumentField) GetResult(org.elasticsearch.index.get.GetResult) SearchDocument(org.springframework.data.elasticsearch.core.document.SearchDocument) Document(org.springframework.data.elasticsearch.core.document.Document) GetResponse(org.elasticsearch.action.get.GetResponse) Test(org.junit.jupiter.api.Test)

Example 38 with Document

use of org.springframework.data.elasticsearch.core.document.Document in project spring-data-elasticsearch by spring-projects.

the class DocumentAdaptersUnitTests method shouldAdaptGetResult.

// DATAES-799, DATAES-848
@Test
public void shouldAdaptGetResult() {
    Map<String, DocumentField> fields = Collections.singletonMap("field", new DocumentField("field", Collections.singletonList("value")));
    GetResult getResult = new GetResult("index", "type", "my-id", 1, 2, 42, true, null, fields, null);
    Document document = DocumentAdapters.from(getResult);
    assertThat(document.getIndex()).isEqualTo("index");
    assertThat(document.hasId()).isTrue();
    assertThat(document.getId()).isEqualTo("my-id");
    assertThat(document.hasVersion()).isTrue();
    assertThat(document.getVersion()).isEqualTo(42);
    assertThat(document.get("field")).isEqualTo("value");
    assertThat(document.hasSeqNo()).isTrue();
    assertThat(document.getSeqNo()).isEqualTo(1);
    assertThat(document.hasPrimaryTerm()).isTrue();
    assertThat(document.getPrimaryTerm()).isEqualTo(2);
}
Also used : DocumentField(org.elasticsearch.common.document.DocumentField) GetResult(org.elasticsearch.index.get.GetResult) SearchDocument(org.springframework.data.elasticsearch.core.document.SearchDocument) Document(org.springframework.data.elasticsearch.core.document.Document) Test(org.junit.jupiter.api.Test)

Example 39 with Document

use of org.springframework.data.elasticsearch.core.document.Document in project spring-data-elasticsearch by spring-projects.

the class DocumentAdaptersUnitTests method shouldAdaptGetResultSource.

// DATAES-799, DATAES-848
@Test
public void shouldAdaptGetResultSource() {
    BytesArray source = new BytesArray("{\"field\":\"value\"}");
    GetResult getResult = new GetResult("index", "type", "my-id", 1, 2, 42, true, source, Collections.emptyMap(), null);
    Document document = DocumentAdapters.from(getResult);
    assertThat(document.getIndex()).isEqualTo("index");
    assertThat(document.hasId()).isTrue();
    assertThat(document.getId()).isEqualTo("my-id");
    assertThat(document.hasVersion()).isTrue();
    assertThat(document.getVersion()).isEqualTo(42);
    assertThat(document.get("field")).isEqualTo("value");
    assertThat(document.hasSeqNo()).isTrue();
    assertThat(document.getSeqNo()).isEqualTo(1);
    assertThat(document.hasPrimaryTerm()).isTrue();
    assertThat(document.getPrimaryTerm()).isEqualTo(2);
}
Also used : BytesArray(org.elasticsearch.common.bytes.BytesArray) GetResult(org.elasticsearch.index.get.GetResult) SearchDocument(org.springframework.data.elasticsearch.core.document.SearchDocument) Document(org.springframework.data.elasticsearch.core.document.Document) Test(org.junit.jupiter.api.Test)

Example 40 with Document

use of org.springframework.data.elasticsearch.core.document.Document in project spring-data-elasticsearch by spring-projects.

the class MappingElasticsearchConverterUnitTests method readEntityWithMapDataType.

// DATAES-763
@Test
void readEntityWithMapDataType() {
    Document document = Document.create();
    document.put("id", 1L);
    document.put("fromEmail", "from@email.com");
    document.put("toEmail", "to@email.com");
    Map<String, Object> data = new HashMap<>();
    data.put("documentType", "abc");
    data.put("content", null);
    document.put("params", data);
    Notification notification = mappingElasticsearchConverter.read(Notification.class, document);
    assertThat(notification.params.get("documentType")).isEqualTo("abc");
    assertThat(notification.params.get("content")).isNull();
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) GeoJsonLineString(org.springframework.data.elasticsearch.core.geo.GeoJsonLineString) GeoJsonMultiLineString(org.springframework.data.elasticsearch.core.geo.GeoJsonMultiLineString) Document(org.springframework.data.elasticsearch.core.document.Document) Test(org.junit.jupiter.api.Test)

Aggregations

Document (org.springframework.data.elasticsearch.core.document.Document)58 Test (org.junit.jupiter.api.Test)48 GeoJsonLineString (org.springframework.data.elasticsearch.core.geo.GeoJsonLineString)15 GeoJsonMultiLineString (org.springframework.data.elasticsearch.core.geo.GeoJsonMultiLineString)15 DisplayName (org.junit.jupiter.api.DisplayName)7 HashMap (java.util.HashMap)6 ArrayList (java.util.ArrayList)5 LinkedHashMap (java.util.LinkedHashMap)5 SpringIntegrationTest (org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)5 GetResult (org.elasticsearch.index.get.GetResult)4 SearchDocument (org.springframework.data.elasticsearch.core.document.SearchDocument)4 Object (java.lang.Object)2 GetResponse (org.elasticsearch.action.get.GetResponse)2 UpdateRequest (org.elasticsearch.action.update.UpdateRequest)2 MappingMetadata (org.elasticsearch.cluster.metadata.MappingMetadata)2 BytesArray (org.elasticsearch.common.bytes.BytesArray)2 DocumentField (org.elasticsearch.common.document.DocumentField)2 GeoPoint (org.springframework.data.elasticsearch.core.geo.GeoPoint)2 AliasData (org.springframework.data.elasticsearch.core.index.AliasData)2 Settings (org.springframework.data.elasticsearch.core.index.Settings)2