Skip to content

Commit

Permalink
Use new approach
Browse files Browse the repository at this point in the history
Signed-off-by: Gao Binlong <gbinlong@amazon.com>
  • Loading branch information
gaobinlong committed Jul 16, 2024
1 parent b3e0394 commit dd79c54
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ public IndexRequest doc() {

private IndexRequest safeDoc() {
if (doc == null) {
doc = new IndexRequest();
doc = new IndexRequest(index);
}
return doc;
}
Expand Down Expand Up @@ -803,7 +803,7 @@ public IndexRequest upsertRequest() {

private IndexRequest safeUpsertRequest() {
if (upsertRequest == null) {
upsertRequest = new IndexRequest();
upsertRequest = new IndexRequest(index);
}
return upsertRequest;
}
Expand Down
17 changes: 7 additions & 10 deletions server/src/main/java/org/opensearch/ingest/IngestService.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,18 +213,11 @@ public static boolean resolvePipelines(
finalPipeline = IndexSettings.FINAL_PIPELINE.get(indexSettings);
indexRequest.setFinalPipeline(finalPipeline);
}
} else if (indexRequest.index() != null || originalRequest != null && originalRequest.index() != null) {
} else if (indexRequest.index() != null) {
// the index does not exist yet (and this is a valid request), so match index
// templates to look for pipelines in either a matching V2 template (which takes
// precedence), or if a V2 template does not match, any V1 templates
String indexName;
if (indexRequest.index() != null) {
indexName = indexRequest.index();
} else {
assert originalRequest != null;
indexName = originalRequest.index();
}
String v2Template = MetadataIndexTemplateService.findV2Template(metadata, indexName, false);
String v2Template = MetadataIndexTemplateService.findV2Template(metadata, indexRequest.index(), false);
if (v2Template != null) {
Settings settings = MetadataIndexTemplateService.resolveSettings(metadata, v2Template);
if (IndexSettings.DEFAULT_PIPELINE.exists(settings)) {
Expand All @@ -238,7 +231,11 @@ public static boolean resolvePipelines(
indexRequest.setPipeline(defaultPipeline != null ? defaultPipeline : NOOP_PIPELINE_NAME);
indexRequest.setFinalPipeline(finalPipeline != null ? finalPipeline : NOOP_PIPELINE_NAME);
} else {
List<IndexTemplateMetadata> templates = MetadataIndexTemplateService.findV1Templates(metadata, indexName, null);
List<IndexTemplateMetadata> templates = MetadataIndexTemplateService.findV1Templates(
metadata,
indexRequest.index(),
null
);
// order of templates are highest order first
for (final IndexTemplateMetadata template : templates) {
final Settings settings = template.settings();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ public void testFromXContent() throws Exception {
assertThat(params, notNullValue());
assertThat(params.size(), equalTo(1));
assertThat(params.get("param1").toString(), equalTo("value1"));
assertThat(request.upsertRequest().index(), equalTo("test"));
Map<String, Object> upsertDoc = XContentHelper.convertToMap(
request.upsertRequest().source(),
true,
Expand Down Expand Up @@ -304,6 +305,7 @@ public void testFromXContent() throws Exception {
)
);
Map<String, Object> doc = request.doc().sourceAsMap();
assertThat(request.doc().index(), equalTo("test"));
assertThat(doc.get("field1").toString(), equalTo("value1"));
assertThat(((Map<String, Object>) doc.get("compound")).get("field2").toString(), equalTo("value2"));
}
Expand Down

0 comments on commit dd79c54

Please sign in to comment.