forked from opensearch-project/opensearch-migrations
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement a simple take on translating RFS bulk requests to use index…
…-type rewrite rules from the type mappings sanitization transformer. Signed-off-by: Greg Schohn <[email protected]>
- Loading branch information
1 parent
73c8e13
commit 739d5d7
Showing
6 changed files
with
78 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{# see https://github.com/opensearch-project/opensearch-migrations/pull/1110 for the format of these messages #} | ||
{%- include "typeMappings/rewriteBulkRequest.j2" -%} | ||
{%- import "typeMappings/rewriteIndexForTarget.j2" as transidx -%} | ||
|
||
{%- set parameters = source_document.index -%} | ||
{{ log_value('ERROR', parameters) }} | ||
{{ log_value('WARN', source_document.source) }} | ||
|
||
{%- set type_name = parameters['_type'] -%} | ||
{%- if type_name -%} | ||
{%- set target_index = transidx.convert_source_index_to_target(parameters['_index'], type_name, input_map.index_mappings, input_map.regex_index_mappings) if type_name -%} | ||
{%- if target_index -%} | ||
{ | ||
{{ rewrite_index_parameters(parameters, target_index) }}, | ||
"source": {{ source_document.source | tojson }} | ||
} | ||
{%- endif -%} | ||
{%- else -%} | ||
{%- import "typeMappings/preserveAll.j2" as preserve -%} | ||
{{- preserve.make_keep_json() -}} | ||
{%- endif -%} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...est/java/org/opensearch/migrations/transform/TypeMappingsSanitizationDocBackfillTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.opensearch.migrations.transform; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
|
||
import org.opensearch.migrations.testutils.JsonNormalizer; | ||
|
||
import lombok.Lombok; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.testcontainers.shaded.com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
@Slf4j | ||
public class TypeMappingsSanitizationDocBackfillTest { | ||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); | ||
|
||
@Test | ||
public void test() throws Exception { | ||
var testString = "{\n" + | ||
" \"index\": { \"_index\": \"performance\", \"_type\": \"network\", \"_id\": \"1\" },\n" + | ||
" \"source\": { \"field1\": \"value1\" }\n" + | ||
"}"; | ||
|
||
var expectedString = "{\n" + | ||
" \"index\": { \"_index\": \"network\", \"_id\": \"1\" },\n" + | ||
" \"source\": { \"field1\": \"value1\" }\n" + | ||
"}"; | ||
|
||
|
||
var regexIndexMappings = List.of(List.of(".*", "", "")); | ||
var indexTypeMappingRewriter = new TypeMappingsSanitizationTransformer(null, regexIndexMappings); | ||
var resultObj = indexTypeMappingRewriter.transformJson(OBJECT_MAPPER.readValue(testString, LinkedHashMap.class)); | ||
log.atInfo().setMessage("resultStr = {}").addArgument(() -> { | ||
try { | ||
return OBJECT_MAPPER.writeValueAsString(resultObj); | ||
} catch (Exception e) { | ||
throw Lombok.sneakyThrow(e); | ||
} | ||
}).log(); | ||
Assertions.assertEquals(JsonNormalizer.fromString(expectedString), JsonNormalizer.fromObject(resultObj)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters