From 1b86c690d23f3b7c44d99cd20467a668ab13a5a7 Mon Sep 17 00:00:00 2001 From: Dhrubo Saha Date: Wed, 2 Oct 2024 09:55:10 -0700 Subject: [PATCH] update config index mappings to use correct field types (#2710) (#2718) (#3053) * update config index mappings to use with correct field types (cherry picked from commit 19266992df17ce73063ebd01acb6981602ffbd94) Co-authored-by: opensearch-trigger-bot[bot] <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Co-authored-by: Bhavana Ramaram --- .../org/opensearch/ml/common/CommonValue.java | 10 ++++--- .../org/opensearch/ml/common/MLConfig.java | 29 +++++++++++++++---- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/common/src/main/java/org/opensearch/ml/common/CommonValue.java b/common/src/main/java/org/opensearch/ml/common/CommonValue.java index 5acbf445ae..4badd5ede6 100644 --- a/common/src/main/java/org/opensearch/ml/common/CommonValue.java +++ b/common/src/main/java/org/opensearch/ml/common/CommonValue.java @@ -13,6 +13,9 @@ import java.util.Set; +import static org.opensearch.ml.common.MLConfig.CONFIG_TYPE_FIELD; +import static org.opensearch.ml.common.MLConfig.LAST_UPDATED_TIME_FIELD; +import static org.opensearch.ml.common.MLConfig.ML_CONFIGURATION_FIELD; import static org.opensearch.ml.common.conversation.ConversationalIndexConstants.APPLICATION_TYPE_FIELD; import static org.opensearch.ml.common.conversation.ConversationalIndexConstants.INTERACTIONS_ADDITIONAL_INFO_FIELD; import static org.opensearch.ml.common.conversation.ConversationalIndexConstants.INTERACTIONS_CONVERSATION_ID_FIELD; @@ -418,25 +421,24 @@ public class CommonValue { + " \"_meta\": {\"schema_version\": " + ML_CONFIG_INDEX_SCHEMA_VERSION + "},\n" - + " \"dynamic\": \"strict\",\n" + " \"properties\": {\n" + " \"" + MASTER_KEY + "\": {\"type\": \"keyword\"},\n" + " \"" - + MLConfig.TYPE_FIELD + + CONFIG_TYPE_FIELD + "\" : {\"type\":\"keyword\"},\n" + " \"" + TENANT_ID + "\" : {\"type\":\"keyword\"},\n" + " \"" - + MLConfig.CONFIGURATION_FIELD + + ML_CONFIGURATION_FIELD + "\" : {\"type\": \"flat_object\"},\n" + " \"" + CREATE_TIME_FIELD + "\": {\"type\": \"date\", \"format\": \"strict_date_time||epoch_millis\"},\n" + " \"" - + LAST_UPDATE_TIME_FIELD + + LAST_UPDATED_TIME_FIELD + "\": {\"type\": \"date\", \"format\": \"strict_date_time||epoch_millis\"}\n" + " }\n" + "}"; diff --git a/common/src/main/java/org/opensearch/ml/common/MLConfig.java b/common/src/main/java/org/opensearch/ml/common/MLConfig.java index 7a3db0be5b..ea529a77b8 100644 --- a/common/src/main/java/org/opensearch/ml/common/MLConfig.java +++ b/common/src/main/java/org/opensearch/ml/common/MLConfig.java @@ -28,11 +28,18 @@ public class MLConfig implements ToXContentObject, Writeable { public static final String TYPE_FIELD = "type"; + public static final String CONFIG_TYPE_FIELD = "config_type"; + public static final String CONFIGURATION_FIELD = "configuration"; + public static final String ML_CONFIGURATION_FIELD = "ml_configuration"; + public static final String CREATE_TIME_FIELD = "create_time"; public static final String LAST_UPDATE_TIME_FIELD = "last_update_time"; + public static final String LAST_UPDATED_TIME_FIELD = "last_updated_time"; + + @Setter private String type; @@ -86,10 +93,10 @@ public void writeTo(StreamOutput out) throws IOException { public XContentBuilder toXContent(XContentBuilder xContentBuilder, Params params) throws IOException { XContentBuilder builder = xContentBuilder.startObject(); if (type != null) { - builder.field(TYPE_FIELD, type); + builder.field(CONFIG_TYPE_FIELD, type); } if (configuration != null) { - builder.field(CONFIGURATION_FIELD, configuration); + builder.field(ML_CONFIGURATION_FIELD, configuration); } if (createTime != null) { builder.field(CREATE_TIME_FIELD, createTime.toEpochMilli()); @@ -109,9 +116,12 @@ public static MLConfig fromStream(StreamInput in) throws IOException { public static MLConfig parse(XContentParser parser) throws IOException { String type = null; + String configType = null; Configuration configuration = null; + Configuration mlConfiguration = null; Instant createTime = null; Instant lastUpdateTime = null; + Instant lastUpdatedTime = null; String tenantId = null; ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.currentToken(), parser); @@ -123,9 +133,15 @@ public static MLConfig parse(XContentParser parser) throws IOException { case TYPE_FIELD: type = parser.text(); break; + case CONFIG_TYPE_FIELD: + configType = parser.text(); + break; case CONFIGURATION_FIELD: configuration = Configuration.parse(parser); break; + case ML_CONFIGURATION_FIELD: + mlConfiguration = Configuration.parse(parser); + break; case CREATE_TIME_FIELD: createTime = Instant.ofEpochMilli(parser.longValue()); break; @@ -135,16 +151,19 @@ public static MLConfig parse(XContentParser parser) throws IOException { case TENANT_ID: tenantId = parser.textOrNull(); break; + case LAST_UPDATED_TIME_FIELD: + lastUpdatedTime = Instant.ofEpochMilli(parser.longValue()); + break; default: parser.skipChildren(); break; } } return MLConfig.builder() - .type(type) - .configuration(configuration) + .type(configType == null ? type : configType) + .configuration(mlConfiguration == null ? configuration : mlConfiguration) .createTime(createTime) - .lastUpdateTime(lastUpdateTime) + .lastUpdateTime(lastUpdatedTime == null ? lastUpdateTime : lastUpdatedTime) .tenantId(tenantId) .build(); }