Skip to content

Conversation

karenyrx
Copy link
Contributor

@karenyrx karenyrx commented Oct 9, 2025

Description

(Stacked on top of https://github.com/opensearch-project/OpenSearch/pull/19568/files)

Implement IndexDocument, UpdateDocument, GetDocument, DeleteDocument GRPC APIs

Example requests

  1. Index Doc (product-1)
grpcurl -plaintext \
  -import-path ~/OpenSearch \
  -proto ~/OpenSearch/protos/services/document_service.proto \
  -d '{
    "index": "demo-index",
    "id": "product-1",
    "bytes_request_body": "eyJ0aXRsZSI6ICJMYXB0b3AgQ29tcHV0ZXIiLCAiY29udGVudCI6ICJIaWdoLXBlcmZvcm1hbmNlIGxhcHRvcCBmb3IgZGV2ZWxvcGVycyIsICJjYXRlZ29yeSI6ICJlbGVjdHJvbmljcyIsICJwcmljZSI6IDEyOTkuOTksICJjcmVhdGVkX2F0IjogIjIwMjUtMTAtMDlUMTQ6MDA6MDBaIn0="
  }' \
  localhost:9400 \
  org.opensearch.protobufs.services.DocumentService/IndexDocument
EOF
{
  "indexDocumentResponseBody": {
    "xId": "product-1",
    "xIndex": "demo-index",
    "xPrimaryTerm": "1",
    "result": "RESULT_CREATED",
    "xSeqNo": "1",
    "xVersion": "1"
  }
}
zsh: command not found: EOF
  1. Create Doc (product-2)
grpcurl -plaintext \
  -import-path ~/OpenSearch \
  -proto ~/OpenSearch/protos/services/document_service.proto \
  -d '{
    "index": "demo-index",
    "id": "product-2",
    "op_type": "OP_TYPE_CREATE",
    "bytes_request_body": "eyJ0aXRsZSI6ICJTbWFydHBob25lIiwgImNvbnRlbnQiOiAiTGF0ZXN0IG1vZGVsIHNtYXJ0cGhvbmUgd2l0aCBhZHZhbmNlZCBmZWF0dXJlcyIsICJjYXRlZ29yeSI6ICJlbGVjdHJvbmljcyIsICJwcmljZSI6IDc5OS45OSwgImNyZWF0ZWRfYXQiOiAiMjAyNS0xMC0wOVQxNDowNTowMFoifQ=="
  }' \
  localhost:9400 \
  org.opensearch.protobufs.services.DocumentService/IndexDocument
EOF
{
  "indexDocumentResponseBody": {
    "xId": "product-2",
    "xIndex": "demo-index",
    "xPrimaryTerm": "1",
    "result": "RESULT_CREATED",
    "xSeqNo": "0",
    "xVersion": "1"
  }
}
  1. Update Doc (product-1)
grpcurl -plaintext \
  -import-path ~/OpenSearch \
  -proto ~/OpenSearch/protos/services/document_service.proto \
  -d '{
    "index": "demo-index",
    "id": "product-1",
    "request_body": {      "bytes_doc": "eyJwcmljZSI6IDExOTkuOTksICJsYXN0X3VwZGF0ZWQiOiAiMjAyNS0xMC0wOVQxNDoxNTowMFoifQ=="    }
  }' \
  localhost:9400 \
  org.opensearch.protobufs.services.DocumentService/UpdateDocument
EOF
{
  "updateDocumentResponseBody": {
    "xId": "product-1",
    "xIndex": "demo-index",
    "xPrimaryTerm": "1",
    "result": "RESULT_UPDATED",
    "xSeqNo": "2",
    "xVersion": "2"
  }
}
  1. Get Doc (product-1)
grpcurl -plaintext \
  -import-path ~/OpenSearch \
  -proto ~/OpenSearch/protos/services/document_service.proto \
  -d '{
    "index": "demo-index",
    "id": "product-1"
  }' \
  localhost:9400 \
  org.opensearch.protobufs.services.DocumentService/GetDocument
EOF
{
  "getDocumentResponseBody": {
    "xIndex": "demo-index",
    "found": true,
    "xId": "product-1",
    "xPrimaryTerm": "1",
    "xSeqNo": "2",
    "xVersion": "2",
    "xSource": "eyJ0aXRsZSI6IkxhcHRvcCBDb21wdXRlciIsImNvbnRlbnQiOiJIaWdoLXBlcmZvcm1hbmNlIGxhcHRvcCBmb3IgZGV2ZWxvcGVycyIsImNhdGVnb3J5IjoiZWxlY3Ryb25pY3MiLCJwcmljZSI6MTI5OS45OSwiY3JlYXRlZF9hdCI6IjIwMjUtMTAtMDlUMTQ6MDA6MDBaIiwib3JnLm9wZW5zZWFyY2guY29yZS5jb21tb24uYnl0ZXMuQnl0ZXNBcnJheUAyZjA1MDg2MCI6IkpTT04ifQ=="
  }
}
  1. Delete Doc (product-1)
grpcurl -plaintext \
  -import-path ~/OpenSearch \
  -proto ~/OpenSearch/protos/services/document_service.proto \
  -d '{
    "index": "demo-index",
    "id": "product-1"
  }' \
  localhost:9400 \
  org.opensearch.protobufs.services.DocumentService/DeleteDocument
{
  "deleteDocumentResponseBody": {
    "xId": "product-1",
    "xIndex": "demo-index",
    "xPrimaryTerm": "1",
    "result": "RESULT_DELETED",
    "xSeqNo": "4",
    "xVersion": "3"
  }
}
  1. Get Doc (product-1) after deletion - Not found
grpcurl -plaintext \
  -import-path ~/OpenSearch \
  -proto ~/OpenSearch/protos/services/document_service.proto \
  -d '{
    "index": "demo-index",
    "id": "product-1"
  }' \
  localhost:9400 \
  org.opensearch.protobufs.services.DocumentService/GetDocument
EOF
{
  "getDocumentResponseBody": {
    "xIndex": "demo-index",
    "found": false,
    "xId": "product-1",
    "xPrimaryTerm": "0",
    "xSeqNo": "-2", # UNASSIGNED_SEQ_NO
    "xVersion": "-1" # NOT_FOUND
  }
}
  1. Error scenario
grpcurl -plaintext \
  -import-path ~/OpenSearch \
  -proto ~/OpenSearch/protos/services/document_service.proto \
  -d @ localhost:9400 \
  org.opensearch.protobufs.services.DocumentService/IndexDocument <<'EOM'
{
  "id": "error-test",
  "bytes_request_body": "eyJ0aXRsZSI6ICJFcnJvciBUZXN0In0="
}
EOM

ERROR:
  Code: InvalidArgument
  Message: java.lang.IllegalArgumentException: Index name is required

Related Issues

Resolves #19572

Check List

  • Functionality includes testing.
  • API changes companion pull request created, if applicable.
  • Public documentation issue/PR created, if applicable.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@github-actions github-actions bot added enhancement Enhancement or improvement to existing feature or request Indexing Indexing, Bulk Indexing and anything related to indexing labels Oct 9, 2025
@karenyrx
Copy link
Contributor Author

karenyrx commented Oct 9, 2025

This PR is not ready for review yet. Protobufs are still under finalization.

Copy link
Contributor

github-actions bot commented Oct 9, 2025

❌ Gradle check result for 7393363: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Enhancement or improvement to existing feature or request Indexing Indexing, Bulk Indexing and anything related to indexing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] Implement basic GRPC single doc ingestion APIs

1 participant