Skip to content

Commit e4a814d

Browse files
committed
Allow index configs to be overwritten
1 parent c231480 commit e4a814d

File tree

2 files changed

+4
-24
lines changed

2 files changed

+4
-24
lines changed

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MlConfigMigrator.java

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import org.apache.logging.log4j.Logger;
1010
import org.elasticsearch.Version;
1111
import org.elasticsearch.action.ActionListener;
12-
import org.elasticsearch.action.DocWriteRequest;
1312
import org.elasticsearch.action.bulk.BulkItemResponse;
1413
import org.elasticsearch.action.bulk.BulkRequestBuilder;
1514
import org.elasticsearch.action.bulk.BulkResponse;
@@ -24,7 +23,6 @@
2423
import org.elasticsearch.common.xcontent.ToXContentObject;
2524
import org.elasticsearch.common.xcontent.XContentBuilder;
2625
import org.elasticsearch.common.xcontent.XContentFactory;
27-
import org.elasticsearch.index.engine.VersionConflictEngineException;
2826
import org.elasticsearch.persistent.PersistentTasksCustomMetaData;
2927
import org.elasticsearch.xpack.core.ml.MlMetadata;
3028
import org.elasticsearch.xpack.core.ml.MlTasks;
@@ -275,8 +273,6 @@ private void addDatafeedIndexRequests(Collection<DatafeedConfig> datafeedConfigs
275273

276274
private IndexRequest indexRequest(ToXContentObject source, String documentId, ToXContent.Params params) {
277275
IndexRequest indexRequest = new IndexRequest(AnomalyDetectorsIndex.configIndexName(), ElasticsearchMappings.DOC_TYPE, documentId);
278-
// do not overwrite existing documents
279-
indexRequest.opType(DocWriteRequest.OpType.CREATE);
280276

281277
try (XContentBuilder builder = XContentFactory.jsonBuilder()) {
282278
indexRequest.source(source.toXContent(builder, params));
@@ -364,15 +360,9 @@ static Set<String> documentsNotWritten(BulkResponse response) {
364360
for (BulkItemResponse itemResponse : response.getItems()) {
365361
if (itemResponse.isFailed()) {
366362
BulkItemResponse.Failure failure = itemResponse.getFailure();
367-
if (failure.getCause().getClass() == VersionConflictEngineException.class) {
368-
// not a failure. The document is already written but perhaps
369-
// has not been removed from the clusterstate
370-
logger.info("cannot write ml configuration [" + itemResponse.getFailure().getId() + "] as it already exists");
371-
} else {
372-
failedDocumentIds.add(itemResponse.getFailure().getId());
373-
logger.info("failed to index ml configuration [" + itemResponse.getFailure().getId() + "], " +
374-
itemResponse.getFailure().getMessage());
375-
}
363+
failedDocumentIds.add(itemResponse.getFailure().getId());
364+
logger.info("failed to index ml configuration [" + itemResponse.getFailure().getId() + "], " +
365+
itemResponse.getFailure().getMessage());
376366
} else {
377367
logger.info("ml configuration [" + itemResponse.getId() + "] indexed");
378368
}

x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MlConfigMigratorTests.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
import org.elasticsearch.cluster.ClusterName;
1212
import org.elasticsearch.cluster.ClusterState;
1313
import org.elasticsearch.cluster.metadata.MetaData;
14-
import org.elasticsearch.index.engine.VersionConflictEngineException;
15-
import org.elasticsearch.index.shard.ShardId;
1614
import org.elasticsearch.persistent.PersistentTasksCustomMetaData;
1715
import org.elasticsearch.test.ESTestCase;
1816
import org.elasticsearch.xpack.core.ml.MlMetadata;
@@ -170,15 +168,7 @@ public void testDocumentsNotWritten() {
170168
when(failure.getCause()).thenReturn(mock(IllegalStateException.class));
171169
when(failed.getFailure()).thenReturn(failure);
172170

173-
BulkItemResponse alreadyExists = mock(BulkItemResponse.class);
174-
when(alreadyExists.isFailed()).thenReturn(true);
175-
BulkItemResponse.Failure alreadyExistsFailure = mock(BulkItemResponse.Failure.class);
176-
when(alreadyExistsFailure.getId()).thenReturn("already-exists-doc-id");
177-
VersionConflictEngineException vcException = new VersionConflictEngineException(new ShardId("i", "i", 0), "doc", "id", "");
178-
when(alreadyExistsFailure.getCause()).thenReturn(vcException);
179-
when(alreadyExists.getFailure()).thenReturn(alreadyExistsFailure);
180-
181-
BulkResponse bulkResponse = new BulkResponse(new BulkItemResponse[] {ok, failed, alreadyExists}, 1L);
171+
BulkResponse bulkResponse = new BulkResponse(new BulkItemResponse[] {ok, failed}, 1L);
182172
Set<String> docsIds = MlConfigMigrator.documentsNotWritten(bulkResponse);
183173
assertThat(docsIds, contains("failed-doc-id"));
184174
}

0 commit comments

Comments
 (0)