From 6b0c475a20b671159b1b4554b4b2ca958a24aae3 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Fri, 26 Jul 2024 18:27:46 -0500 Subject: [PATCH] Add XContentType to wrap the CreateIndexRequest mappings in _doc key to fix v1 templates issue (#2759) (#2766) * Add XContentType to wrap the CreateIndexRequest mappings in _doc key to fix v1 templates issue Signed-off-by: Bhavana Ramaram (cherry picked from commit 1c43be5ff4c7aaf6c64b7b8a9de06e840d08767a) Co-authored-by: Bhavana Ramaram (cherry picked from commit 389dd954d52525117640af122ac5c14cf09d8922) --- .../org/opensearch/ml/memory/index/ConversationMetaIndex.java | 3 ++- .../java/org/opensearch/ml/memory/index/InteractionsIndex.java | 3 ++- .../algorithms/metrics_correlation/MetricsCorrelation.java | 3 ++- .../org/opensearch/ml/engine/indices/MLIndicesHandler.java | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/memory/src/main/java/org/opensearch/ml/memory/index/ConversationMetaIndex.java b/memory/src/main/java/org/opensearch/ml/memory/index/ConversationMetaIndex.java index 21fba2bf9d..d4dde66326 100644 --- a/memory/src/main/java/org/opensearch/ml/memory/index/ConversationMetaIndex.java +++ b/memory/src/main/java/org/opensearch/ml/memory/index/ConversationMetaIndex.java @@ -46,6 +46,7 @@ import org.opensearch.client.Requests; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.util.concurrent.ThreadContext; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.commons.ConfigConstants; import org.opensearch.commons.authuser.User; import org.opensearch.core.action.ActionListener; @@ -87,7 +88,7 @@ public void initConversationMetaIndexIfAbsent(ActionListener listener) log.debug("No conversational meta index found. Adding it"); CreateIndexRequest request = Requests .createIndexRequest(META_INDEX_NAME) - .mapping(ConversationalIndexConstants.META_MAPPING) + .mapping(ConversationalIndexConstants.META_MAPPING, XContentType.JSON) .settings(INDEX_SETTINGS); try (ThreadContext.StoredContext threadContext = client.threadPool().getThreadContext().stashContext()) { ActionListener internalListener = ActionListener.runBefore(listener, () -> threadContext.restore()); diff --git a/memory/src/main/java/org/opensearch/ml/memory/index/InteractionsIndex.java b/memory/src/main/java/org/opensearch/ml/memory/index/InteractionsIndex.java index 0911a5785c..ad31485e50 100644 --- a/memory/src/main/java/org/opensearch/ml/memory/index/InteractionsIndex.java +++ b/memory/src/main/java/org/opensearch/ml/memory/index/InteractionsIndex.java @@ -46,6 +46,7 @@ import org.opensearch.client.Requests; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.util.concurrent.ThreadContext; +import org.opensearch.common.xcontent.XContentType; import org.opensearch.commons.ConfigConstants; import org.opensearch.commons.authuser.User; import org.opensearch.core.action.ActionListener; @@ -90,7 +91,7 @@ public void initInteractionsIndexIfAbsent(ActionListener listener) { log.debug("No messages index found. Adding it"); CreateIndexRequest request = Requests .createIndexRequest(INTERACTIONS_INDEX_NAME) - .mapping(ConversationalIndexConstants.INTERACTIONS_MAPPINGS) + .mapping(ConversationalIndexConstants.INTERACTIONS_MAPPINGS, XContentType.JSON) .settings(INDEX_SETTINGS); try (ThreadContext.StoredContext threadContext = client.threadPool().getThreadContext().stashContext()) { ActionListener internalListener = ActionListener.runBefore(listener, () -> threadContext.restore()); diff --git a/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/metrics_correlation/MetricsCorrelation.java b/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/metrics_correlation/MetricsCorrelation.java index ec35db0ed1..8491f397d7 100644 --- a/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/metrics_correlation/MetricsCorrelation.java +++ b/ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/metrics_correlation/MetricsCorrelation.java @@ -129,7 +129,8 @@ public void execute(Input input, ActionListener listener) internalListener.onFailure(e); } }); - CreateIndexRequest request = new CreateIndexRequest(indexName).mapping(mapping).settings(INDEX_SETTINGS); + CreateIndexRequest request = new CreateIndexRequest(indexName).mapping(mapping, XContentType.JSON).settings(INDEX_SETTINGS); client.admin().indices().create(request, actionListener); } else { log.debug("index:{} is already created", indexName);