/** * Register custom {@link Converter}s in a {@link ElasticsearchCustomConversions} object if required. * * @return never {@literal null}. */ @Bean public ElasticsearchCustomConversions customConversions() { return new ElasticsearchCustomConversions(Collections.emptyList()); }
public ElasticsearchRestTemplate(RestHighLevelClient client, ElasticsearchConverter elasticsearchConverter, EntityMapper entityMapper) { this(client, elasticsearchConverter, new DefaultResultMapper(elasticsearchConverter.getMappingContext(), entityMapper)); }
private String convertId(Object id) { return elasticsearchOperations.getElasticsearchConverter().convertId(id); } }
@Bean public ElasticsearchConverter elasticsearchConverter() { return new MappingElasticsearchConverter(elasticsearchMappingContext()); }
@Nullable private Object getConvertedValue(Object value) { if (value == null) { return "null"; } if (converter.getConversionService().canConvert(value.getClass(), String.class)) { return converter.getConversionService().convert(value, String.class); } return value.toString(); } }
/** * Creates a {@link SimpleElasticsearchMappingContext} equipped with entity classes scanned from the mapping base * package. * * @see #getMappingBasePackages() * @return never {@literal null}. */ @Bean @SneakyThrows public SimpleElasticsearchMappingContext elasticsearchMappingContext() { SimpleElasticsearchMappingContext mappingContext = new SimpleElasticsearchMappingContext(); mappingContext.setInitialEntitySet(getInitialEntitySet()); mappingContext.setSimpleTypeHolder(customConversions().getSimpleTypeHolder()); return mappingContext; }
public ElasticsearchRestTemplate(RestHighLevelClient client, ElasticsearchConverter elasticsearchConverter) { this(client, elasticsearchConverter, new DefaultResultMapper(elasticsearchConverter.getMappingContext())); }
public ReactiveElasticsearchTemplate(ReactiveElasticsearchClient client) { this(client, new MappingElasticsearchConverter(new SimpleElasticsearchMappingContext())); }
@Override public Mono<String> delete(Object entity, @Nullable String index, @Nullable String type) { Entity<?> elasticsearchEntity = operations.forEntity(entity); return Mono.defer(() -> doDeleteById(entity, converter.convertId(elasticsearchEntity.getId()), elasticsearchEntity.getPersistentEntity(), index, type)); }
@Override public <T> Mono<T> save(T entity, @Nullable String index, @Nullable String type) { Assert.notNull(entity, "Entity must not be null!"); AdaptibleEntity<T> adaptableEntity = operations.forEntity(entity, converter.getConversionService()); return doIndex(entity, adaptableEntity, index, type) // .map(it -> { return adaptableEntity.populateIdIfNecessary(it.getId()); }); }
protected MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> getMappingContext() { return elasticsearchOperations.getElasticsearchConverter().getMappingContext(); } }
public ElasticsearchRestTemplate(RestHighLevelClient client) { this(client, new MappingElasticsearchConverter(new SimpleElasticsearchMappingContext())); }
private Mono<IndexResponse> doIndex(Object value, AdaptibleEntity<?> entity, @Nullable String index, @Nullable String type) { return Mono.defer(() -> { Object id = entity.getId(); IndexCoordinates indexCoordinates = operations.determineIndex(entity, index, type); IndexRequest request = id != null ? new IndexRequest(indexCoordinates.getIndexName(), indexCoordinates.getTypeName(), converter.convertId(id)) : new IndexRequest(indexCoordinates.getIndexName(), indexCoordinates.getTypeName()); try { request.source(resultMapper.getEntityMapper().mapToString(value), Requests.INDEX_CONTENT_TYPE); } catch (IOException e) { throw new RuntimeException(e); } if (entity.isVersionedEntity()) { Object version = entity.getVersion(); if (version != null) { request.version(((Number) version).longValue()); request.versionType(EXTERNAL); } } if (entity.hasParent()) { Object parentId = entity.getParentId(); if (parentId != null) { request.parent(converter.convertId(parentId)); } } request = prepareIndexRequest(value, request); return doIndex(request); }); }
/** * Creates a new {@link ReactiveElasticsearchRepositoryFactory} with the given * {@link ReactiveElasticsearchOperations}. * * @param elasticsearchOperations must not be {@literal null}. */ public ReactiveElasticsearchRepositoryFactory(ReactiveElasticsearchOperations elasticsearchOperations) { Assert.notNull(elasticsearchOperations, "ReactiveElasticsearchOperations must not be null!"); this.operations = elasticsearchOperations; this.mappingContext = elasticsearchOperations.getElasticsearchConverter().getMappingContext(); }
public ElasticsearchRestTemplate(RestHighLevelClient client, ResultsMapper resultsMapper) { this(client, new MappingElasticsearchConverter(new SimpleElasticsearchMappingContext()), resultsMapper); }
@Override public ElasticsearchPersistentEntity getPersistentEntityFor(Class clazz) { Assert.isTrue(clazz.isAnnotationPresent(Document.class), "Unable to identify index name. " + clazz.getSimpleName() + " is not a Document. Make sure the document class is annotated with @Document(indexName=\"foo\")"); return elasticsearchConverter.getMappingContext().getRequiredPersistentEntity(clazz); }
public ElasticsearchRestTemplate(RestHighLevelClient client, EntityMapper entityMapper) { this(client, new MappingElasticsearchConverter(new SimpleElasticsearchMappingContext()), entityMapper); }
public ReactiveElasticsearchTemplate(ReactiveElasticsearchClient client, ElasticsearchConverter converter) { this.client = client; this.converter = converter; this.mappingContext = converter.getMappingContext(); this.resultMapper = new DefaultResultMapper(converter.getMappingContext()); this.exceptionTranslator = new ElasticsearchExceptionTranslator(); this.operations = new EntityOperations(this.mappingContext); }
public ElasticsearchTemplate(Client client, ElasticsearchConverter elasticsearchConverter) { this.client = client; this.elasticsearchConverter = (elasticsearchConverter == null)? new MappingElasticsearchConverter(new SimpleElasticsearchMappingContext()) : elasticsearchConverter ; }
@Override public void afterPropertiesSet() { super.afterPropertiesSet(); Assert.state(operations != null, "ReactiveElasticsearchOperations must not be null!"); if (!mappingContextConfigured) { setMappingContext(operations.getElasticsearchConverter().getMappingContext()); } } }