Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,13 @@ public static IndexConfiguration readIndexConfig(final OpenSearchSinkConfig open
builder = builder.withScriptConfiguration(scriptConfiguration);
}

if (scriptConfiguration != null && openSearchSinkConfig.getVersionType() != null
&& VersionType.External.jsonValue().equals(openSearchSinkConfig.getVersionType())) {
throw new InvalidPluginConfigurationException(
"document_version_type 'external' is incompatible with script configuration. " +
"OpenSearch does not support external versioning with scripted upserts.");
}

AwsAuthenticationConfiguration awsAuthenticationConfiguration = openSearchSinkConfig.getAwsAuthenticationOptions();
if (awsAuthenticationConfiguration != null) {
builder = builder.withServerless(awsAuthenticationConfiguration.isServerlessCollection());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -653,4 +653,26 @@ private String createTemplateContent() {
"\"mappings\":{\"properties\":{\"timestamp\":{\"type\":\"date\",\"format\":\"yyyy-MM-ddHH:mm:ss||yyyy-MM-dd||epoch_millis\"}," +
"\"value\":{\"type\":\"double\"}}}}}";
}

@Test
public void testReadIndexConfig_withExternalVersionAndScript_throws_InvalidPluginConfigurationException() throws JsonProcessingException {
final Map<String, Object> metadata = new HashMap<>();
metadata.put("index_type", "custom");
metadata.put("index", "test-index");
metadata.put("document_version_type", "external");
metadata.put("script", Map.of("source", "ctx._source.counter += 1"));
final OpenSearchSinkConfig openSearchSinkConfig = getOpenSearchSinkConfig(metadata);
assertThrows(InvalidPluginConfigurationException.class, () -> IndexConfiguration.readIndexConfig(openSearchSinkConfig));
}

@Test
public void testReadIndexConfig_withScriptAndNoExternalVersion_doesNotThrow() throws JsonProcessingException {
final Map<String, Object> metadata = new HashMap<>();
metadata.put("index_type", "custom");
metadata.put("index", "test-index");
metadata.put("script", Map.of("source", "ctx._source.counter += 1"));
final OpenSearchSinkConfig openSearchSinkConfig = getOpenSearchSinkConfig(metadata);
final IndexConfiguration config = IndexConfiguration.readIndexConfig(openSearchSinkConfig);
assertThat(config.getScriptConfiguration(), notNullValue());
}
}
Loading