diff --git a/src/main/java/org/elasticsearch/action/deletebyquery/TransportShardDeleteByQueryAction.java b/src/main/java/org/elasticsearch/action/deletebyquery/TransportShardDeleteByQueryAction.java index 7f2cd83497c..89fbd36ec6c 100644 --- a/src/main/java/org/elasticsearch/action/deletebyquery/TransportShardDeleteByQueryAction.java +++ b/src/main/java/org/elasticsearch/action/deletebyquery/TransportShardDeleteByQueryAction.java @@ -92,7 +92,8 @@ public class TransportShardDeleteByQueryAction extends TransportShardReplication protected PrimaryResponse shardOperationOnPrimary(ClusterState clusterState, PrimaryOperationRequest shardRequest) { ShardDeleteByQueryRequest request = shardRequest.request; IndexShard indexShard = indicesService.indexServiceSafe(shardRequest.request.index()).shardSafe(shardRequest.shardId); - Engine.DeleteByQuery deleteByQuery = indexShard.prepareDeleteByQuery(request.querySource(), request.filteringAliases(), request.types()); + Engine.DeleteByQuery deleteByQuery = indexShard.prepareDeleteByQuery(request.querySource(), request.filteringAliases(), request.types()) + .origin(Engine.Operation.Origin.PRIMARY); indexShard.deleteByQuery(deleteByQuery); return new PrimaryResponse(shardRequest.request, new ShardDeleteByQueryResponse(), null); } @@ -102,7 +103,8 @@ public class TransportShardDeleteByQueryAction extends TransportShardReplication protected void shardOperationOnReplica(ReplicaOperationRequest shardRequest) { ShardDeleteByQueryRequest request = shardRequest.request; IndexShard indexShard = indicesService.indexServiceSafe(shardRequest.request.index()).shardSafe(shardRequest.shardId); - Engine.DeleteByQuery deleteByQuery = indexShard.prepareDeleteByQuery(request.querySource(), request.filteringAliases(), request.types()); + Engine.DeleteByQuery deleteByQuery = indexShard.prepareDeleteByQuery(request.querySource(), request.filteringAliases(), request.types()) + .origin(Engine.Operation.Origin.REPLICA); indexShard.deleteByQuery(deleteByQuery); } diff --git a/src/main/java/org/elasticsearch/index/engine/Engine.java b/src/main/java/org/elasticsearch/index/engine/Engine.java index d917ef85050..5f0d8144069 100644 --- a/src/main/java/org/elasticsearch/index/engine/Engine.java +++ b/src/main/java/org/elasticsearch/index/engine/Engine.java @@ -748,6 +748,7 @@ public interface Engine extends IndexShardComponent, CloseableComponent { private final Filter aliasFilter; private final String[] types; private final Filter parentFilter; + private Operation.Origin origin = Operation.Origin.PRIMARY; private long startTime; private long endTime; @@ -789,6 +790,15 @@ public interface Engine extends IndexShardComponent, CloseableComponent { return parentFilter; } + public DeleteByQuery origin(Operation.Origin origin) { + this.origin = origin; + return this; + } + + public Operation.Origin origin() { + return this.origin; + } + public DeleteByQuery startTime(long startTime) { this.startTime = startTime; return this; diff --git a/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java b/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java index f96d8ef3570..4689d1129c5 100644 --- a/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java +++ b/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java @@ -691,7 +691,8 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I break; case DELETE_BY_QUERY: Translog.DeleteByQuery deleteByQuery = (Translog.DeleteByQuery) operation; - engine.delete(prepareDeleteByQuery(deleteByQuery.source(), deleteByQuery.filteringAliases(), deleteByQuery.types())); + engine.delete(prepareDeleteByQuery(deleteByQuery.source(), deleteByQuery.filteringAliases(), deleteByQuery.types()) + .origin(Engine.Operation.Origin.RECOVERY)); break; default: throw new ElasticSearchIllegalStateException("No operation defined for [" + operation + "]");