Skip to content

Commit ac02864

Browse files
Add XContentType to wrap the CreateIndexRequest mappings in _doc key to fix v1 templates issue (opensearch-project#2759) (opensearch-project#2764)
* Add XContentType to wrap the CreateIndexRequest mappings in _doc key to fix v1 templates issue Signed-off-by: Bhavana Ramaram <rbhavna@amazon.com> (cherry picked from commit 1c43be5) Co-authored-by: Bhavana Ramaram <rbhavna@amazon.com>
1 parent 951bf1d commit ac02864

File tree

4 files changed

+7
-4
lines changed

4 files changed

+7
-4
lines changed

memory/src/main/java/org/opensearch/ml/memory/index/ConversationMetaIndex.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.opensearch.client.Requests;
4747
import org.opensearch.cluster.service.ClusterService;
4848
import org.opensearch.common.util.concurrent.ThreadContext;
49+
import org.opensearch.common.xcontent.XContentType;
4950
import org.opensearch.commons.ConfigConstants;
5051
import org.opensearch.commons.authuser.User;
5152
import org.opensearch.core.action.ActionListener;
@@ -87,7 +88,7 @@ public void initConversationMetaIndexIfAbsent(ActionListener<Boolean> listener)
8788
log.debug("No conversational meta index found. Adding it");
8889
CreateIndexRequest request = Requests
8990
.createIndexRequest(META_INDEX_NAME)
90-
.mapping(ConversationalIndexConstants.META_MAPPING)
91+
.mapping(ConversationalIndexConstants.META_MAPPING, XContentType.JSON)
9192
.settings(INDEX_SETTINGS);
9293
try (ThreadContext.StoredContext threadContext = client.threadPool().getThreadContext().stashContext()) {
9394
ActionListener<Boolean> internalListener = ActionListener.runBefore(listener, () -> threadContext.restore());

memory/src/main/java/org/opensearch/ml/memory/index/InteractionsIndex.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.opensearch.client.Requests;
4747
import org.opensearch.cluster.service.ClusterService;
4848
import org.opensearch.common.util.concurrent.ThreadContext;
49+
import org.opensearch.common.xcontent.XContentType;
4950
import org.opensearch.commons.ConfigConstants;
5051
import org.opensearch.commons.authuser.User;
5152
import org.opensearch.core.action.ActionListener;
@@ -90,7 +91,7 @@ public void initInteractionsIndexIfAbsent(ActionListener<Boolean> listener) {
9091
log.debug("No messages index found. Adding it");
9192
CreateIndexRequest request = Requests
9293
.createIndexRequest(INTERACTIONS_INDEX_NAME)
93-
.mapping(ConversationalIndexConstants.INTERACTIONS_MAPPINGS)
94+
.mapping(ConversationalIndexConstants.INTERACTIONS_MAPPINGS, XContentType.JSON)
9495
.settings(INDEX_SETTINGS);
9596
try (ThreadContext.StoredContext threadContext = client.threadPool().getThreadContext().stashContext()) {
9697
ActionListener<Boolean> internalListener = ActionListener.runBefore(listener, () -> threadContext.restore());

ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/metrics_correlation/MetricsCorrelation.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ public void execute(Input input, ActionListener<org.opensearch.ml.common.output.
129129
boolean hasModelGroupIndex = clusterService.state().getMetadata().hasIndex(ML_MODEL_GROUP_INDEX);
130130
if (!hasModelGroupIndex) { // Create model group index if it doesn't exist
131131
try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().stashContext()) {
132-
CreateIndexRequest request = new CreateIndexRequest(ML_MODEL_GROUP_INDEX).mapping(ML_MODEL_GROUP_INDEX_MAPPING);
132+
CreateIndexRequest request = new CreateIndexRequest(ML_MODEL_GROUP_INDEX)
133+
.mapping(ML_MODEL_GROUP_INDEX_MAPPING, XContentType.JSON);
133134
CreateIndexResponse createIndexResponse = client.admin().indices().create(request).actionGet(1000);
134135
if (!createIndexResponse.isAcknowledged()) {
135136
throw new MLException("Failed to create model group index");

ml-algorithms/src/main/java/org/opensearch/ml/engine/indices/MLIndicesHandler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public void initMLIndexIfAbsent(MLIndex index, ActionListener<Boolean> listener)
108108
internalListener.onFailure(e);
109109
}
110110
});
111-
CreateIndexRequest request = new CreateIndexRequest(indexName).mapping(mapping).settings(INDEX_SETTINGS);
111+
CreateIndexRequest request = new CreateIndexRequest(indexName).mapping(mapping, XContentType.JSON).settings(INDEX_SETTINGS);
112112
client.admin().indices().create(request, actionListener);
113113
} else {
114114
log.debug("index:{} is already created", indexName);

0 commit comments

Comments
 (0)