use of org.springframework.data.elasticsearch.core.document.Document in project spring-data-elasticsearch by spring-projects.
the class ElasticsearchTemplateTests method shouldDoUpsertIfDocumentDoesNotExist.
@Test
public void shouldDoUpsertIfDocumentDoesNotExist() {
// given
String documentId = nextIdAsString();
org.springframework.data.elasticsearch.core.document.Document document = org.springframework.data.elasticsearch.core.document.Document.create();
document.put("message", "test message");
UpdateQuery updateQuery = //
UpdateQuery.builder(documentId).withDocument(//
document).withDocAsUpsert(//
true).build();
// when
operations.update(updateQuery, IndexCoordinates.of(indexNameProvider.indexName()));
// then
SampleEntity indexedEntity = operations.get(documentId, SampleEntity.class, IndexCoordinates.of(indexNameProvider.indexName()));
assertThat(indexedEntity.getMessage()).isEqualTo("test message");
}
use of org.springframework.data.elasticsearch.core.document.Document in project spring-data-elasticsearch by spring-projects.
the class ReactiveIndexTemplate method getMapping.
@Override
public Mono<Document> getMapping() {
IndexCoordinates indexCoordinates = getIndexCoordinates();
GetMappingsRequest request = requestFactory.getMappingsRequest(indexCoordinates);
return Mono.from(operations.executeWithIndicesClient(client -> client.getMapping(request))).flatMap(getMappingsResponse -> {
Map<String, Object> source = getMappingsResponse.mappings().get(indexCoordinates.getIndexName()).getSourceAsMap();
Document document = Document.from(source);
return Mono.just(document);
});
}
use of org.springframework.data.elasticsearch.core.document.Document in project spring-data-elasticsearch by spring-projects.
the class ResponseConverter method getIndexInformations.
// endregion
// region index informations
/**
* get the index informations from a {@link GetIndexResponse}
*
* @param getIndexResponse the index response, must not be {@literal null}
* @return list of {@link IndexInformation}s for the different indices
*/
public static List<IndexInformation> getIndexInformations(GetIndexResponse getIndexResponse) {
Assert.notNull(getIndexResponse, "getIndexResponse must not be null");
List<IndexInformation> indexInformationList = new ArrayList<>();
for (String indexName : getIndexResponse.getIndices()) {
Settings settings = settingsFromGetIndexResponse(getIndexResponse, indexName);
Document mappings = mappingsFromGetIndexResponse(getIndexResponse, indexName);
List<AliasData> aliases = aliasDataFromIndexResponse(getIndexResponse, indexName);
indexInformationList.add(IndexInformation.of(indexName, settings, mappings, aliases));
}
return indexInformationList;
}
use of org.springframework.data.elasticsearch.core.document.Document in project spring-data-elasticsearch by spring-projects.
the class ElasticsearchTemplateTests method toDocument.
private org.springframework.data.elasticsearch.core.document.Document toDocument(JoinField joinField) {
org.springframework.data.elasticsearch.core.document.Document document = create();
document.put("name", joinField.getName());
document.put("parent", joinField.getParent());
return document;
}
use of org.springframework.data.elasticsearch.core.document.Document in project spring-data-elasticsearch by spring-projects.
the class ElasticsearchTemplateTests method shouldUseUpsertOnUpdate.
// DATAES-227
@Test
public void shouldUseUpsertOnUpdate() {
// given
Map<String, Object> doc = new HashMap<>();
doc.put("id", "1");
doc.put("message", "test");
org.springframework.data.elasticsearch.core.document.Document document = org.springframework.data.elasticsearch.core.document.Document.from(doc);
UpdateQuery updateQuery = //
UpdateQuery.builder("1").withDocument(//
document).withUpsert(//
document).build();
// when
UpdateRequest request = getRequestFactory().updateRequest(updateQuery, IndexCoordinates.of("index"));
// then
assertThat(request).isNotNull();
assertThat(request.upsertRequest()).isNotNull();
}
Aggregations