Skip to content

Commit c9ce062

Browse files
update config index mappings to use correct field types (#2710) (#2717)
* update config index mappings to use with correct field types Signed-off-by: Bhavana Ramaram <[email protected]> Signed-off-by: Bhavana Ramaram <[email protected]> (cherry picked from commit 1926699) Co-authored-by: Bhavana Ramaram <[email protected]>
1 parent ed0169f commit c9ce062

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

common/src/main/java/org/opensearch/ml/common/CommonValue.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
import java.util.Set;
1515

16+
import static org.opensearch.ml.common.MLConfig.CONFIG_TYPE_FIELD;
17+
import static org.opensearch.ml.common.MLConfig.LAST_UPDATED_TIME_FIELD;
18+
import static org.opensearch.ml.common.MLConfig.ML_CONFIGURATION_FIELD;
1619
import static org.opensearch.ml.common.conversation.ConversationalIndexConstants.APPLICATION_TYPE_FIELD;
1720
import static org.opensearch.ml.common.conversation.ConversationalIndexConstants.INTERACTIONS_ADDITIONAL_INFO_FIELD;
1821
import static org.opensearch.ml.common.conversation.ConversationalIndexConstants.INTERACTIONS_CONVERSATION_ID_FIELD;
@@ -407,22 +410,21 @@ public class CommonValue {
407410
+ " \"_meta\": {\"schema_version\": "
408411
+ ML_CONFIG_INDEX_SCHEMA_VERSION
409412
+ "},\n"
410-
+ " \"dynamic\": \"strict\",\n"
411413
+ " \"properties\": {\n"
412414
+ " \""
413415
+ MASTER_KEY
414416
+ "\": {\"type\": \"keyword\"},\n"
415417
+ " \""
416-
+ MLConfig.TYPE_FIELD
418+
+ CONFIG_TYPE_FIELD
417419
+ "\" : {\"type\":\"keyword\"},\n"
418420
+ " \""
419-
+ MLConfig.CONFIGURATION_FIELD
421+
+ ML_CONFIGURATION_FIELD
420422
+ "\" : {\"type\": \"flat_object\"},\n"
421423
+ " \""
422424
+ CREATE_TIME_FIELD
423425
+ "\": {\"type\": \"date\", \"format\": \"strict_date_time||epoch_millis\"},\n"
424426
+ " \""
425-
+ LAST_UPDATE_TIME_FIELD
427+
+ LAST_UPDATED_TIME_FIELD
426428
+ "\": {\"type\": \"date\", \"format\": \"strict_date_time||epoch_millis\"}\n"
427429
+ " }\n"
428430
+ "}";

common/src/main/java/org/opensearch/ml/common/MLConfig.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,18 @@ public class MLConfig implements ToXContentObject, Writeable {
2727

2828
public static final String TYPE_FIELD = "type";
2929

30+
public static final String CONFIG_TYPE_FIELD = "config_type";
31+
3032
public static final String CONFIGURATION_FIELD = "configuration";
3133

34+
public static final String ML_CONFIGURATION_FIELD = "ml_configuration";
35+
3236
public static final String CREATE_TIME_FIELD = "create_time";
3337
public static final String LAST_UPDATE_TIME_FIELD = "last_update_time";
3438

39+
public static final String LAST_UPDATED_TIME_FIELD = "last_updated_time";
40+
41+
3542
@Setter
3643
private String type;
3744

@@ -78,10 +85,10 @@ public void writeTo(StreamOutput out) throws IOException {
7885
public XContentBuilder toXContent(XContentBuilder xContentBuilder, Params params) throws IOException {
7986
XContentBuilder builder = xContentBuilder.startObject();
8087
if (type != null) {
81-
builder.field(TYPE_FIELD, type);
88+
builder.field(CONFIG_TYPE_FIELD, type);
8289
}
8390
if (configuration != null) {
84-
builder.field(CONFIGURATION_FIELD, configuration);
91+
builder.field(ML_CONFIGURATION_FIELD, configuration);
8592
}
8693
if (createTime != null) {
8794
builder.field(CREATE_TIME_FIELD, createTime.toEpochMilli());
@@ -99,9 +106,12 @@ public static MLConfig fromStream(StreamInput in) throws IOException {
99106

100107
public static MLConfig parse(XContentParser parser) throws IOException {
101108
String type = null;
109+
String configType = null;
102110
Configuration configuration = null;
111+
Configuration mlConfiguration = null;
103112
Instant createTime = null;
104113
Instant lastUpdateTime = null;
114+
Instant lastUpdatedTime = null;
105115

106116
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.currentToken(), parser);
107117
while (parser.nextToken() != XContentParser.Token.END_OBJECT) {
@@ -112,25 +122,34 @@ public static MLConfig parse(XContentParser parser) throws IOException {
112122
case TYPE_FIELD:
113123
type = parser.text();
114124
break;
125+
case CONFIG_TYPE_FIELD:
126+
configType = parser.text();
127+
break;
115128
case CONFIGURATION_FIELD:
116129
configuration = Configuration.parse(parser);
117130
break;
131+
case ML_CONFIGURATION_FIELD:
132+
mlConfiguration = Configuration.parse(parser);
133+
break;
118134
case CREATE_TIME_FIELD:
119135
createTime = Instant.ofEpochMilli(parser.longValue());
120136
break;
121137
case LAST_UPDATE_TIME_FIELD:
122138
lastUpdateTime = Instant.ofEpochMilli(parser.longValue());
123139
break;
140+
case LAST_UPDATED_TIME_FIELD:
141+
lastUpdatedTime = Instant.ofEpochMilli(parser.longValue());
142+
break;
124143
default:
125144
parser.skipChildren();
126145
break;
127146
}
128147
}
129148
return MLConfig.builder()
130-
.type(type)
131-
.configuration(configuration)
149+
.type(configType == null ? type : configType)
150+
.configuration(mlConfiguration == null ? configuration : mlConfiguration)
132151
.createTime(createTime)
133-
.lastUpdateTime(lastUpdateTime)
152+
.lastUpdateTime(lastUpdatedTime == null ? lastUpdateTime : lastUpdatedTime)
134153
.build();
135154
}
136155
}

0 commit comments

Comments
 (0)