Skip to content

Commit

Permalink
Add XContentType to wrap the CreateIndexRequest mappings in _doc key …
Browse files Browse the repository at this point in the history
…to fix v1 templates issue (#2759) (#2763)

* Add XContentType to wrap the CreateIndexRequest mappings in _doc key to fix v1 templates issue

Signed-off-by: Bhavana Ramaram <[email protected]>
(cherry picked from commit 1c43be5)

Co-authored-by: Bhavana Ramaram <[email protected]>
  • Loading branch information
opensearch-trigger-bot[bot] and rbhavna authored Jul 26, 2024
1 parent bc159b1 commit 446a592
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -87,7 +88,7 @@ public void initConversationMetaIndexIfAbsent(ActionListener<Boolean> 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<Boolean> internalListener = ActionListener.runBefore(listener, () -> threadContext.restore());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -90,7 +91,7 @@ public void initInteractionsIndexIfAbsent(ActionListener<Boolean> 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<Boolean> internalListener = ActionListener.runBefore(listener, () -> threadContext.restore());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ public void execute(Input input, ActionListener<org.opensearch.ml.common.output.
boolean hasModelGroupIndex = clusterService.state().getMetadata().hasIndex(ML_MODEL_GROUP_INDEX);
if (!hasModelGroupIndex) { // Create model group index if it doesn't exist
try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().stashContext()) {
CreateIndexRequest request = new CreateIndexRequest(ML_MODEL_GROUP_INDEX).mapping(ML_MODEL_GROUP_INDEX_MAPPING);
CreateIndexRequest request = new CreateIndexRequest(ML_MODEL_GROUP_INDEX)
.mapping(ML_MODEL_GROUP_INDEX_MAPPING, XContentType.JSON);
CreateIndexResponse createIndexResponse = client.admin().indices().create(request).actionGet(1000);
if (!createIndexResponse.isAcknowledged()) {
throw new MLException("Failed to create model group index");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void initMLIndexIfAbsent(MLIndex index, ActionListener<Boolean> 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);
Expand Down

0 comments on commit 446a592

Please sign in to comment.