Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support format expressions for routing in the opensearch sink #3863

Merged
merged 5 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -479,11 +479,11 @@ private SerializedJson getDocument(final Event event) {
if (routingField != null) {
routingValue = event.get(routingField, String.class);
} else if (routing != null) {
if (expressionEvaluator.isValidFormatExpression(routing)) {
routingValue = event.formatString(routing, expressionEvaluator);
} else {
routingValue = event.get(routing, String.class);
}
try {
routingValue = event.formatString(routing, expressionEvaluator);
} catch (final ExpressionEvaluationException | EventKeyNotFoundException e) {
LOG.error("Unable to construct routing with format {}, the document_id will be generated by OpenSearch", routing, e);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy past error for document_id here. However, the routing is different from document id a bit, as it defaults to being the same value as document_id (https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-routing-field.html). So we should change this to

 LOG.error("Unable to construct routing with format {}, the routing will default to being the same as the document_id", routing, e);

}
}

final String document = DocumentBuilder.build(event, documentRootKey, sinkContext.getTagsTargetKey(), sinkContext.getIncludeKeys(), sinkContext.getExcludeKeys());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public static IndexConfiguration readIndexConfig(final PluginSetting pluginSetti
final String routingField = pluginSetting.getStringOrDefault(ROUTING_FIELD, null);
final String routing = pluginSetting.getStringOrDefault(ROUTING, null);
if (routingField != null) {
LOG.warn("routing_field is deprecated in favor of routing, and support for document_field will be removed in a future major version release.");
LOG.warn("routing_field is deprecated in favor of routing, and support for routing_field will be removed in a future major version release.");
builder = builder.withRoutingField(routingField);
} else if (routing != null) {
builder = builder.withRouting(routing);
Expand Down
Loading