Search in sources :

Example 56 with DeleteRequest

use of org.elasticsearch.action.delete.DeleteRequest in project yacy_grid_mcp by yacy.

the class ElasticsearchClient method deleteBulk.

/**
 * Delete a list of documents for a given set of ids
 * ATTENTION: read about the time-out of version number checking in the method above.
 *
 * @param ids
 *            a map from the unique identifier of a document to the document type
 * @return the number of deleted documents
 */
public int deleteBulk(String indexName, Map<String, String> ids) {
    // bulk-delete the ids
    if (ids == null || ids.size() == 0)
        return 0;
    BulkRequestBuilder bulkRequest = elasticsearchClient.prepareBulk();
    for (Map.Entry<String, String> id : ids.entrySet()) {
        bulkRequest.add(new DeleteRequest().id(id.getKey()).index(indexName).type(id.getValue()));
    }
    bulkRequest.execute().actionGet();
    return ids.size();
}
Also used : BulkRequestBuilder(org.elasticsearch.action.bulk.BulkRequestBuilder) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) AbstractMap(java.util.AbstractMap) TreeMap(java.util.TreeMap) DeleteRequest(org.elasticsearch.action.delete.DeleteRequest)

Example 57 with DeleteRequest

use of org.elasticsearch.action.delete.DeleteRequest in project pinpoint by naver.

the class ElasticsearchExecutorInterceptor method recordeESattributes.

// TODO max dsl limit need
private void recordeESattributes(SpanEventRecorder recorder, Object target, Object[] args, Object result, Throwable throwable) {
    if (recordESVersion) {
        if (target instanceof ClusterInfoAccessor) {
            // record elasticsearch version and cluster name.
            recorder.recordAttribute(ElasticsearchConstants.ARGS_VERSION_ANNOTATION_KEY, ((ClusterInfoAccessor) target)._$PINPOINT$_getClusterInfo());
        }
    }
    if (recordDsl) {
        if (args[0] instanceof SearchRequest) {
            SearchRequest request = (SearchRequest) args[0];
            recorder.recordAttribute(ElasticsearchConstants.ARGS_DSL_ANNOTATION_KEY, StringUtils.abbreviate(request.source().toString(), 256));
        } else if (args[0] instanceof GetRequest) {
            // GetRequest request = (GetRequest) args[0];
            recorder.recordAttribute(ElasticsearchConstants.ARGS_DSL_ANNOTATION_KEY, StringUtils.abbreviate(args[0].toString(), 256));
        } else if (args[0] instanceof IndexRequest) {
            // IndexRequest request = (IndexRequest) args[0];
            recorder.recordAttribute(ElasticsearchConstants.ARGS_DSL_ANNOTATION_KEY, StringUtils.abbreviate(args[0].toString(), 256));
        } else if (args[0] instanceof DeleteRequest) {
            // DeleteRequest request = (DeleteRequest) args[0];
            recorder.recordAttribute(ElasticsearchConstants.ARGS_DSL_ANNOTATION_KEY, StringUtils.abbreviate(args[0].toString(), 256));
        } else if (args[0] instanceof UpdateRequest) {
            // UpdateRequest request = (UpdateRequest) args[0];
            recorder.recordAttribute(ElasticsearchConstants.ARGS_DSL_ANNOTATION_KEY, StringUtils.abbreviate(args[0].toString(), 256));
        }
    }
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) UpdateRequest(org.elasticsearch.action.update.UpdateRequest) ClusterInfoAccessor(com.navercorp.pinpoint.plugin.elasticsearch.accessor.ClusterInfoAccessor) GetRequest(org.elasticsearch.action.get.GetRequest) IndexRequest(org.elasticsearch.action.index.IndexRequest) DeleteRequest(org.elasticsearch.action.delete.DeleteRequest)

Aggregations

DeleteRequest (org.elasticsearch.action.delete.DeleteRequest)57 IndexRequest (org.elasticsearch.action.index.IndexRequest)35 UpdateRequest (org.elasticsearch.action.update.UpdateRequest)24 BulkRequest (org.elasticsearch.action.bulk.BulkRequest)16 IOException (java.io.IOException)15 DocWriteRequest (org.elasticsearch.action.DocWriteRequest)11 DeleteResponse (org.elasticsearch.action.delete.DeleteResponse)11 Map (java.util.Map)9 HashMap (java.util.HashMap)8 ElasticsearchException (org.elasticsearch.ElasticsearchException)7 DeleteIndexRequest (org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 BulkItemResponse (org.elasticsearch.action.bulk.BulkItemResponse)6 BulkRequestBuilder (org.elasticsearch.action.bulk.BulkRequestBuilder)6 BulkResponse (org.elasticsearch.action.bulk.BulkResponse)6 GetRequest (org.elasticsearch.action.get.GetRequest)5 SearchRequest (org.elasticsearch.action.search.SearchRequest)5 BytesReference (org.elasticsearch.common.bytes.BytesReference)5 XContentType (org.elasticsearch.common.xcontent.XContentType)5