Skip to content

feat: Add support for routing_keys in index_documents #3148

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

wvivek
Copy link

@wvivek wvivek commented May 14, 2025

Adding support for routing_keys in the index_documents API. The routing_keys is a optional argument when provided will compound the keys joining with _ and add as the routing key for indexing.

Feature or Bugfix

  • Feature

Detail

  • index_documents does not support routing keys. This is to include support for routing_keys.

Relates

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Adding support for routing_keys in the index_documents API. The routing_keys is a optional argument when provided will compound the keys joining with _ and add as the routing key for indexing.
@wvivek wvivek changed the title Add support for routing_keys in index_documents feat: Add support for routing_keys in index_documents May 14, 2025
@jaidisido
Copy link
Contributor

AWS CodeBuild CI Report

  • CodeBuild project: GitHubCodeBuild8756EF16-4rfo0GHQ0u9a
  • Commit ID: aa81c27
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@jaidisido
Copy link
Contributor

AWS CodeBuild CI Report

  • CodeBuild project: GitHubDistributedCodeBuild6-jWcl5DLmvupS
  • Commit ID: aa81c27
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

Copy link
Contributor

@kukushking kukushking left a comment

Choose a reason for hiding this comment

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

@wvivek thanks for opening a PR. This looks like you are building parts of your application logic in the SDK. Is _routing key an accepted industry standard? Could you instead add the field to your documents before running index_documents?

@wvivek
Copy link
Author

wvivek commented May 16, 2025

@wvivek thanks for opening a PR. This looks like you are building parts of your application logic in the SDK. Is _routing key an accepted industry standard? Could you instead add the field to your documents before running index_documents?

@kukushking The _routing is provided by OpenSearch to route the documents to specific index. By default OpenSearch uses the _id field to determine the shard. If _routing is provided as part of the indexing call, OpenSearch will make use of the value in the _routing to determine the shard. The search on the index also supports routing filters.
Here is the details of this documented in https://docs.opensearch.org/docs/latest/field-types/metadata-fields/routing/

@kukushking
Copy link
Contributor

kukushking commented May 23, 2025

@kukushking The _routing is provided by OpenSearch to route the documents to specific index. By default OpenSearch uses the _id field to determine the shard. If _routing is provided as part of the indexing call, OpenSearch will make use of the value in the _routing to determine the shard. The search on the index also supports routing filters.
Here is the details of this documented in https://docs.opensearch.org/docs/latest/field-types/metadata-fields/routing/

Thanks @wvivek. Is below a convention for _routing values though? What is used for _routing can vary between users, and we would rather not build this logic into the SDK. In addition, this seems to overwrite the values which would be a breaking change.

routing = "-".join([str(document[routing_key]) for routing_key in routing_keys])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants