Search in sources :

Example 1 with UpdateResponse

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

the class ReactiveElasticsearchTemplate method update.

@Override
public Mono<UpdateResponse> update(UpdateQuery updateQuery, IndexCoordinates index) {
    Assert.notNull(updateQuery, "UpdateQuery must not be null");
    Assert.notNull(index, "Index must not be null");
    return Mono.defer(() -> {
        UpdateRequest request = requestFactory.updateRequest(updateQuery, index);
        if (updateQuery.getRefreshPolicy() == null && refreshPolicy != null) {
            request.setRefreshPolicy(RequestFactory.toElasticsearchRefreshPolicy(refreshPolicy));
        }
        if (updateQuery.getRouting() == null && routingResolver.getRouting() != null) {
            request.routing(routingResolver.getRouting());
        }
        return Mono.from(execute(client -> client.update(request))).map(response -> new UpdateResponse(UpdateResponse.Result.valueOf(response.getResult().name())));
    });
}
Also used : UpdateResponse(org.springframework.data.elasticsearch.core.query.UpdateResponse) UpdateRequest(org.elasticsearch.action.update.UpdateRequest)

Example 2 with UpdateResponse

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

the class ElasticsearchRestTemplate method update.

@Override
public UpdateResponse update(UpdateQuery query, IndexCoordinates index) {
    UpdateRequest request = requestFactory.updateRequest(query, index);
    if (query.getRefreshPolicy() == null && getRefreshPolicy() != null) {
        request.setRefreshPolicy(RequestFactory.toElasticsearchRefreshPolicy(getRefreshPolicy()));
    }
    if (query.getRouting() == null && routingResolver.getRouting() != null) {
        request.routing(routingResolver.getRouting());
    }
    UpdateResponse.Result result = UpdateResponse.Result.valueOf(execute(client -> client.update(request, RequestOptions.DEFAULT)).getResult().name());
    return new UpdateResponse(result);
}
Also used : GetResponse(org.elasticsearch.action.get.GetResponse) ClusterOperations(org.springframework.data.elasticsearch.core.cluster.ClusterOperations) MoreLikeThisQuery(org.springframework.data.elasticsearch.core.query.MoreLikeThisQuery) QueryBuilders(org.elasticsearch.index.query.QueryBuilders) BulkFailureException(org.springframework.data.elasticsearch.BulkFailureException) DeleteRequest(org.elasticsearch.action.delete.DeleteRequest) IndexRequest(org.elasticsearch.action.index.IndexRequest) ReindexRequest(org.springframework.data.elasticsearch.core.reindex.ReindexRequest) Map(java.util.Map) SearchResponse(org.elasticsearch.action.search.SearchResponse) RequestOptions(org.elasticsearch.client.RequestOptions) DeleteByQueryRequest(org.elasticsearch.index.reindex.DeleteByQueryRequest) TimeValue(org.elasticsearch.core.TimeValue) GetRequest(org.elasticsearch.action.get.GetRequest) MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) IndexCoordinates(org.springframework.data.elasticsearch.core.mapping.IndexCoordinates) UpdateQuery(org.springframework.data.elasticsearch.core.query.UpdateQuery) BulkItemResponse(org.elasticsearch.action.bulk.BulkItemResponse) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) IndexQuery(org.springframework.data.elasticsearch.core.query.IndexQuery) Collectors(java.util.stream.Collectors) MultiSearchResponse(org.elasticsearch.action.search.MultiSearchResponse) List(java.util.List) Stream(java.util.stream.Stream) Version(org.elasticsearch.Version) LogFactory(org.apache.commons.logging.LogFactory) FetchSourceContext(org.elasticsearch.search.fetch.subphase.FetchSourceContext) ClearScrollRequest(org.elasticsearch.action.search.ClearScrollRequest) MultiGetRequest(org.elasticsearch.action.get.MultiGetRequest) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Query(org.springframework.data.elasticsearch.core.query.Query) SearchRequest(org.elasticsearch.action.search.SearchRequest) ElasticsearchClusterOperations(org.springframework.data.elasticsearch.core.cluster.ElasticsearchClusterOperations) BulkOptions(org.springframework.data.elasticsearch.core.query.BulkOptions) ArrayList(java.util.ArrayList) SearchDocumentResponse(org.springframework.data.elasticsearch.core.document.SearchDocumentResponse) WriteRequest(org.elasticsearch.action.support.WriteRequest) DocumentAdapters(org.springframework.data.elasticsearch.core.document.DocumentAdapters) ByQueryResponse(org.springframework.data.elasticsearch.core.query.ByQueryResponse) ElasticsearchConverter(org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter) MultiSearchRequest(org.elasticsearch.action.search.MultiSearchRequest) IndexResponse(org.elasticsearch.action.index.IndexResponse) Nullable(org.springframework.lang.Nullable) MoreLikeThisQueryBuilder(org.elasticsearch.index.query.MoreLikeThisQueryBuilder) UpdateResponse(org.springframework.data.elasticsearch.core.query.UpdateResponse) UpdateByQueryRequest(org.elasticsearch.index.reindex.UpdateByQueryRequest) BulkByScrollResponse(org.elasticsearch.index.reindex.BulkByScrollResponse) Iterator(java.util.Iterator) IOException(java.io.IOException) UpdateRequest(org.elasticsearch.action.update.UpdateRequest) DocWriteResponse(org.elasticsearch.action.DocWriteResponse) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient) SuggestBuilder(org.elasticsearch.search.suggest.SuggestBuilder) Log(org.apache.commons.logging.Log) NativeSearchQueryBuilder(org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder) SearchScrollRequest(org.elasticsearch.action.search.SearchScrollRequest) BulkRequest(org.elasticsearch.action.bulk.BulkRequest) ReindexResponse(org.springframework.data.elasticsearch.core.reindex.ReindexResponse) Assert(org.springframework.util.Assert) UpdateResponse(org.springframework.data.elasticsearch.core.query.UpdateResponse) UpdateRequest(org.elasticsearch.action.update.UpdateRequest)

Example 3 with UpdateResponse

use of org.springframework.data.elasticsearch.core.query.UpdateResponse in project IT-Demo by yanghaiji.

the class EsTempWeb method update.

/**
 * <p>
 * 更新
 * </p>
 *
 * @param
 * @return void
 * @version 1.0.0
 * @author hai ji
 * @since 2022/2/9
 */
@PostMapping
public void update() {
    Document document = Document.create();
    document.put("title", 1214666);
    document.put("price", 66.6);
    UpdateQuery updateQuery = UpdateQuery.builder("164439571754").withDocument(document).build();
    // 单条更新
    UpdateResponse response = elasticsearchTemplate.update(updateQuery, IndexCoordinates.of("sys_user"));
    System.out.println(response.getResult().name());
    // 批量更新
    List<UpdateQuery> list = new LinkedList<>();
    list.add(updateQuery);
    elasticsearchTemplate.bulkUpdate(list, IndexCoordinates.of("sys_user"));
}
Also used : UpdateResponse(org.springframework.data.elasticsearch.core.query.UpdateResponse) UpdateQuery(org.springframework.data.elasticsearch.core.query.UpdateQuery) Document(org.springframework.data.elasticsearch.core.document.Document) LinkedList(java.util.LinkedList)

Aggregations

UpdateResponse (org.springframework.data.elasticsearch.core.query.UpdateResponse)3 UpdateRequest (org.elasticsearch.action.update.UpdateRequest)2 UpdateQuery (org.springframework.data.elasticsearch.core.query.UpdateQuery)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Log (org.apache.commons.logging.Log)1 LogFactory (org.apache.commons.logging.LogFactory)1 Version (org.elasticsearch.Version)1 DocWriteResponse (org.elasticsearch.action.DocWriteResponse)1 BulkItemResponse (org.elasticsearch.action.bulk.BulkItemResponse)1 BulkRequest (org.elasticsearch.action.bulk.BulkRequest)1 BulkResponse (org.elasticsearch.action.bulk.BulkResponse)1