Skip to content

Commit

Permalink
use XContentType to add the _doc wrapper
Browse files Browse the repository at this point in the history
Signed-off-by: Bhavana Ramaram <[email protected]>
  • Loading branch information
rbhavna committed Jul 26, 2024
1 parent cea9faf commit 25572e0
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 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("{\"_doc\":" + 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("{\"_doc\":" + 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 @@ -131,7 +131,7 @@ public void execute(Input input, ActionListener<org.opensearch.ml.common.output.
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("{\"_doc\":" + ML_MODEL_GROUP_INDEX_MAPPING + "}");
.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,9 +108,7 @@ public void initMLIndexIfAbsent(MLIndex index, ActionListener<Boolean> listener)
internalListener.onFailure(e);
}
});
CreateIndexRequest request = new CreateIndexRequest(indexName)
.mapping("{\"_doc\":" + 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 25572e0

Please sign in to comment.