|
|
@@ -25,6 +25,7 @@ import org.elasticsearch.action.RoutingMissingException;
|
|
|
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
|
|
|
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
|
|
|
import org.elasticsearch.action.admin.indices.create.TransportCreateIndexAction;
|
|
|
+import org.elasticsearch.action.index.IndexRequest.OpType;
|
|
|
import org.elasticsearch.action.support.ActionFilters;
|
|
|
import org.elasticsearch.action.support.AutoCreateIndex;
|
|
|
import org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction;
|
|
|
@@ -172,62 +173,39 @@ public class TransportIndexAction extends TransportShardReplicationOperationActi
|
|
|
IndexShard indexShard = indexService.shardSafe(shardRequest.shardId.id());
|
|
|
SourceToParse sourceToParse = SourceToParse.source(SourceToParse.Origin.PRIMARY, request.source()).type(request.type()).id(request.id())
|
|
|
.routing(request.routing()).parent(request.parent()).timestamp(request.timestamp()).ttl(request.ttl());
|
|
|
- long version;
|
|
|
- boolean created;
|
|
|
|
|
|
+ final Engine.IndexingOperation operation;
|
|
|
if (request.opType() == IndexRequest.OpType.INDEX) {
|
|
|
- Engine.Index index = indexShard.prepareIndex(sourceToParse, request.version(), request.versionType(), Engine.Operation.Origin.PRIMARY, request.canHaveDuplicates());
|
|
|
- Mapping update = index.parsedDoc().dynamicMappingsUpdate();
|
|
|
- if (update != null) {
|
|
|
- final String indexName = indexService.index().name();
|
|
|
- if (indexName.equals(RiverIndexName.Conf.indexName(settings))) {
|
|
|
- // With rivers, we have a chicken and egg problem if indexing
|
|
|
- // the _meta document triggers a mapping update. Because we would
|
|
|
- // like to validate the mapping update first, but on the other
|
|
|
- // hand putting the mapping would start the river, which expects
|
|
|
- // to find a _meta document
|
|
|
- // So we have no choice but to index first and send mappings afterwards
|
|
|
- MapperService mapperService = indexService.mapperService();
|
|
|
- mapperService.merge(request.type(), new CompressedString(update.toBytes()), true);
|
|
|
- indexShard.index(index);
|
|
|
- mappingUpdatedAction.updateMappingOnMasterAsynchronously(indexName, request.type(), update);
|
|
|
- } else {
|
|
|
- mappingUpdatedAction.updateMappingOnMasterSynchronously(indexName, request.type(), update);
|
|
|
- indexShard.index(index);
|
|
|
- }
|
|
|
- } else {
|
|
|
- indexShard.index(index);
|
|
|
- }
|
|
|
- version = index.version();
|
|
|
- created = index.created();
|
|
|
+ operation = indexShard.prepareIndex(sourceToParse, request.version(), request.versionType(), Engine.Operation.Origin.PRIMARY, request.canHaveDuplicates());
|
|
|
} else {
|
|
|
assert request.opType() == IndexRequest.OpType.CREATE : request.opType();
|
|
|
- Engine.Create create = indexShard.prepareCreate(sourceToParse,
|
|
|
+ operation = indexShard.prepareCreate(sourceToParse,
|
|
|
request.version(), request.versionType(), Engine.Operation.Origin.PRIMARY, request.canHaveDuplicates(), request.autoGeneratedId());
|
|
|
- Mapping update = create.parsedDoc().dynamicMappingsUpdate();
|
|
|
- if (update != null) {
|
|
|
- final String indexName = indexService.index().name();
|
|
|
- if (indexName.equals(RiverIndexName.Conf.indexName(settings))) {
|
|
|
- // With rivers, we have a chicken and egg problem if indexing
|
|
|
- // the _meta document triggers a mapping update. Because we would
|
|
|
- // like to validate the mapping update first, but on the other
|
|
|
- // hand putting the mapping would start the river, which expects
|
|
|
- // to find a _meta document
|
|
|
- // So we have no choice but to index first and send mappings afterwards
|
|
|
- MapperService mapperService = indexService.mapperService();
|
|
|
- mapperService.merge(request.type(), new CompressedString(update.toBytes()), true);
|
|
|
- indexShard.create(create);
|
|
|
- mappingUpdatedAction.updateMappingOnMasterAsynchronously(indexName, request.type(), update);
|
|
|
- } else {
|
|
|
- mappingUpdatedAction.updateMappingOnMasterSynchronously(indexName, request.type(), update);
|
|
|
- indexShard.create(create);
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+ final boolean created;
|
|
|
+ Mapping update = operation.parsedDoc().dynamicMappingsUpdate();
|
|
|
+ if (update != null) {
|
|
|
+ final String indexName = indexService.index().name();
|
|
|
+ if (indexName.equals(RiverIndexName.Conf.indexName(settings))) {
|
|
|
+ // With rivers, we have a chicken and egg problem if indexing
|
|
|
+ // the _meta document triggers a mapping update. Because we would
|
|
|
+ // like to validate the mapping update first, but on the other
|
|
|
+ // hand putting the mapping would start the river, which expects
|
|
|
+ // to find a _meta document
|
|
|
+ // So we have no choice but to index first and send mappings afterwards
|
|
|
+ MapperService mapperService = indexService.mapperService();
|
|
|
+ mapperService.merge(request.type(), new CompressedString(update.toBytes()), true);
|
|
|
+ created = operation.execute(indexShard);
|
|
|
+ mappingUpdatedAction.updateMappingOnMasterAsynchronously(indexName, request.type(), update);
|
|
|
} else {
|
|
|
- indexShard.create(create);
|
|
|
+ mappingUpdatedAction.updateMappingOnMasterSynchronously(indexName, request.type(), update);
|
|
|
+ created = operation.execute(indexShard);
|
|
|
}
|
|
|
- version = create.version();
|
|
|
- created = true;
|
|
|
+ } else {
|
|
|
+ created = operation.execute(indexShard);
|
|
|
}
|
|
|
+
|
|
|
if (request.refresh()) {
|
|
|
try {
|
|
|
indexShard.refresh("refresh_flag_index");
|
|
|
@@ -237,6 +215,7 @@ public class TransportIndexAction extends TransportShardReplicationOperationActi
|
|
|
}
|
|
|
|
|
|
// update the version on the request, so it will be used for the replicas
|
|
|
+ final long version = operation.version();
|
|
|
request.version(version);
|
|
|
request.versionType(request.versionType().versionTypeForReplicationAndRecovery());
|
|
|
|
|
|
@@ -250,22 +229,19 @@ public class TransportIndexAction extends TransportShardReplicationOperationActi
|
|
|
IndexShard indexShard = indexService.shardSafe(shardId.id());
|
|
|
SourceToParse sourceToParse = SourceToParse.source(SourceToParse.Origin.REPLICA, request.source()).type(request.type()).id(request.id())
|
|
|
.routing(request.routing()).parent(request.parent()).timestamp(request.timestamp()).ttl(request.ttl());
|
|
|
+
|
|
|
+ final Engine.IndexingOperation operation;
|
|
|
if (request.opType() == IndexRequest.OpType.INDEX) {
|
|
|
- Engine.Index index = indexShard.prepareIndex(sourceToParse, request.version(), request.versionType(), Engine.Operation.Origin.REPLICA, request.canHaveDuplicates());
|
|
|
- Mapping update = index.parsedDoc().dynamicMappingsUpdate();
|
|
|
- if (update != null) {
|
|
|
- throw new RetryOnReplicaException(shardId, "Mappings are not available on the replica yet, triggered update: " + update);
|
|
|
- }
|
|
|
- indexShard.index(index);
|
|
|
+ operation = indexShard.prepareIndex(sourceToParse, request.version(), request.versionType(), Engine.Operation.Origin.REPLICA, request.canHaveDuplicates());
|
|
|
} else {
|
|
|
assert request.opType() == IndexRequest.OpType.CREATE : request.opType();
|
|
|
- Engine.Create create = indexShard.prepareCreate(sourceToParse, request.version(), request.versionType(), Engine.Operation.Origin.REPLICA, request.canHaveDuplicates(), request.autoGeneratedId());
|
|
|
- Mapping update = create.parsedDoc().dynamicMappingsUpdate();
|
|
|
- if (update != null) {
|
|
|
- throw new RetryOnReplicaException(shardId, "Mappings are not available on the replica yet, triggered update: " + update);
|
|
|
- }
|
|
|
- indexShard.create(create);
|
|
|
+ operation = indexShard.prepareCreate(sourceToParse, request.version(), request.versionType(), Engine.Operation.Origin.REPLICA, request.canHaveDuplicates(), request.autoGeneratedId());
|
|
|
+ }
|
|
|
+ Mapping update = operation.parsedDoc().dynamicMappingsUpdate();
|
|
|
+ if (update != null) {
|
|
|
+ throw new RetryOnReplicaException(shardId, "Mappings are not available on the replica yet, triggered update: " + update);
|
|
|
}
|
|
|
+ operation.execute(indexShard);
|
|
|
if (request.refresh()) {
|
|
|
try {
|
|
|
indexShard.refresh("refresh_flag_index");
|