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

Documents ids with slashes cause issues in high-level client #37405

Closed
javanna opened this issue Jan 14, 2019 · 3 comments
Closed

Documents ids with slashes cause issues in high-level client #37405

javanna opened this issue Jan 14, 2019 · 3 comments
Labels
>bug Team:Data Management Meta label for data/management team

Comments

@javanna
Copy link
Member

javanna commented Jan 14, 2019

This issue was originated from #36988 . When using the high-level REST client to get/index/update documents, slashes in ids can cause problems. This has to do with the logic that encodes each url part separately and then puts the result together in RequestConverters. The following test fails while I think it should succeed. What I think happens at the moment is that the document gets indexed with a different id than the one provided.

public void testIdWithSlashes() throws IOException {
       IndexRequest indexRequest = new IndexRequest("dev_product");
       indexRequest.id("/sku/test.com/48923AQ3");
       indexRequest.source("field", "value");
       IndexResponse indexResponse = highLevelClient().index(indexRequest, RequestOptions.DEFAULT);

       assertEquals("/sku/test.com/48923AQ3", indexResponse.getId());

       GetResponse getResponse = highLevelClient()
           .get(new GetRequest("dev_product", "/sku/test.com/48923AQ3"), RequestOptions.DEFAULT);
       assertTrue(getResponse.isExists());
   }
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-features

@martijnvg
Copy link
Member

This is how the id is received when the index request is sent via the HLRC: test.com/48923AQ3
The /sku/ is missing.

I think the problem is in the EndpointBuilder#encodePart(...) method in RequestCoverters.java line 1106. I think in the case that the pathPart starts with a / then it should not add extra leading slash.

This is a more targeted test:

EndpointBuilder endpointBuilder = new EndpointBuilder().addPathPart("/sku/test.com/48923AQ3");
assertEquals("/%2Fsku%2Ftest.com%2F48923AQ3", endpointBuilder.build());

@dakrone dakrone assigned dakrone and unassigned martijnvg Jan 23, 2019
@rjernst rjernst added the Team:Data Management Meta label for data/management team label May 4, 2020
@dakrone dakrone removed their assignment Aug 31, 2021
@iverase
Copy link
Contributor

iverase commented Sep 2, 2021

It seems this issue has been fixed in #34436 so it can be closed? the examples given here pass successfully.

@javanna javanna closed this as completed Jan 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug Team:Data Management Meta label for data/management team
Projects
None yet
Development

No branches or pull requests

6 participants