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);
}
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);
}
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);
}
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);
}
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();
}
Aggregations