-
Notifications
You must be signed in to change notification settings - Fork 26k
Add query param include_source_on_error for ingest requests
#120725
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
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
8e1f6ba
Adding query param include_source_on_error to optionally disable retu…
mosche b347b12
cleanup
mosche d7aeccb
Merge branch 'main' into xcontent/includeSourceOnError
mosche b05a743
fix
mosche c3aee56
Merge branch 'main' into xcontent/includeSourceOnError
mosche 1bcbac2
Update docs/changelog/120725.yaml
mosche a01b45b
[CI] Auto commit changes from spotless
6bafa83
Merge branch 'main' into xcontent/includeSourceOnError
mosche 77f4138
review
mosche 4d1ff9d
Merge branch 'main' into xcontent/includeSourceOnError
mosche 3eae9e1
update api specs
mosche 6a3e74a
Make includeSourceOnError nullable to control default in a single place
mosche c380dea
do not apply includeSourceOnError silently to all content parsers
mosche 78d3878
Merge branch 'main' into xcontent/includeSourceOnError
mosche e54173a
Revert "Make includeSourceOnError nullable to control default in a si…
mosche a911e45
fix after revert
mosche 9f83956
changelog
mosche f30bb94
Merge branch 'main' into xcontent/includeSourceOnError
mosche File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| pr: 120725 | ||
| summary: |- | ||
| A new query parameter `?include_source_on_error` was added for create / index, update and bulk REST APIs to control | ||
| if to include the document source in the error response in case of parsing errors. The default value is `true`. | ||
| area: Infra/REST API | ||
| type: enhancement | ||
| issues: [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...src/internalClusterTest/java/org/elasticsearch/rest/action/document/RestBulkActionIT.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the "Elastic License | ||
| * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| package org.elasticsearch.rest.action.document; | ||
|
|
||
| import org.elasticsearch.client.Request; | ||
| import org.elasticsearch.client.Response; | ||
| import org.elasticsearch.client.ResponseException; | ||
| import org.elasticsearch.common.Strings; | ||
| import org.elasticsearch.common.io.Streams; | ||
| import org.elasticsearch.rest.RestUtils; | ||
| import org.elasticsearch.test.ESIntegTestCase; | ||
|
|
||
| import java.io.InputStreamReader; | ||
|
|
||
| import static java.nio.charset.StandardCharsets.UTF_8; | ||
| import static org.hamcrest.Matchers.both; | ||
| import static org.hamcrest.Matchers.containsString; | ||
| import static org.hamcrest.Matchers.not; | ||
|
|
||
| public class RestBulkActionIT extends ESIntegTestCase { | ||
| @Override | ||
| protected boolean addMockHttpTransport() { | ||
| return false; | ||
| } | ||
|
|
||
| public void testBulkIndexWithSourceOnErrorDisabled() throws Exception { | ||
| var source = "{\"field\": \"index\",}"; | ||
| var sourceEscaped = "{\\\"field\\\": \\\"index\\\",}"; | ||
|
|
||
| var request = new Request("PUT", "/test_index/_bulk"); | ||
| request.setJsonEntity(Strings.format("{\"index\":{\"_id\":\"1\"}}\n%s\n", source)); | ||
|
|
||
| Response response = getRestClient().performRequest(request); | ||
| String responseContent = Streams.copyToString(new InputStreamReader(response.getEntity().getContent(), UTF_8)); | ||
| assertThat(responseContent, containsString(sourceEscaped)); | ||
|
|
||
| request.addParameter(RestUtils.INCLUDE_SOURCE_ON_ERROR_PARAMETER, "false"); | ||
|
|
||
| response = getRestClient().performRequest(request); | ||
| responseContent = Streams.copyToString(new InputStreamReader(response.getEntity().getContent(), UTF_8)); | ||
| assertThat( | ||
| responseContent, | ||
| both(not(containsString(sourceEscaped))).and( | ||
| containsString("REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled)") | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| public void testBulkUpdateWithSourceOnErrorDisabled() throws Exception { | ||
| var source = "{\"field\": \"index\",}"; | ||
| var sourceEscaped = "{\\\"field\\\": \\\"index\\\",}"; | ||
|
|
||
| var request = new Request("PUT", "/test_index/_bulk"); | ||
| request.addParameter(RestUtils.INCLUDE_SOURCE_ON_ERROR_PARAMETER, "false"); | ||
| request.setJsonEntity(Strings.format("{\"update\":{\"_id\":\"1\"}}\n{\"doc\":%s}}\n", source)); | ||
|
|
||
| // note: this behavior is not consistent with bulk index actions | ||
| // In case of updates by doc, the source is eagerly parsed and will fail the entire request if it cannot be parsed | ||
| var exception = assertThrows(ResponseException.class, () -> getRestClient().performRequest(request)); | ||
| String response = Streams.copyToString(new InputStreamReader(exception.getResponse().getEntity().getContent(), UTF_8)); | ||
|
|
||
| assertThat( | ||
| response, | ||
| both(not(containsString(sourceEscaped))).and( | ||
| containsString("REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled)") | ||
| ) | ||
| ); | ||
| } | ||
| } |
53 changes: 53 additions & 0 deletions
53
...rc/internalClusterTest/java/org/elasticsearch/rest/action/document/RestIndexActionIT.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the "Elastic License | ||
| * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| package org.elasticsearch.rest.action.document; | ||
|
|
||
| import org.elasticsearch.client.Request; | ||
| import org.elasticsearch.client.ResponseException; | ||
| import org.elasticsearch.common.io.Streams; | ||
| import org.elasticsearch.rest.RestUtils; | ||
| import org.elasticsearch.test.ESIntegTestCase; | ||
|
|
||
| import java.io.InputStreamReader; | ||
|
|
||
| import static java.nio.charset.StandardCharsets.UTF_8; | ||
| import static org.hamcrest.Matchers.both; | ||
| import static org.hamcrest.Matchers.containsString; | ||
| import static org.hamcrest.Matchers.not; | ||
|
|
||
| public class RestIndexActionIT extends ESIntegTestCase { | ||
| @Override | ||
| protected boolean addMockHttpTransport() { | ||
| return false; | ||
| } | ||
|
|
||
| public void testIndexWithSourceOnErrorDisabled() throws Exception { | ||
| var source = "{\"field\": \"value}"; | ||
| var sourceEscaped = "{\\\"field\\\": \\\"value}"; | ||
|
|
||
| var request = new Request("POST", "/test_index/_doc/1"); | ||
| request.setJsonEntity(source); | ||
|
|
||
| var exception = assertThrows(ResponseException.class, () -> getRestClient().performRequest(request)); | ||
| String response = Streams.copyToString(new InputStreamReader(exception.getResponse().getEntity().getContent(), UTF_8)); | ||
| assertThat(response, containsString(sourceEscaped)); | ||
|
|
||
| // disable source on error | ||
| request.addParameter(RestUtils.INCLUDE_SOURCE_ON_ERROR_PARAMETER, "false"); | ||
| exception = assertThrows(ResponseException.class, () -> getRestClient().performRequest(request)); | ||
| response = Streams.copyToString(new InputStreamReader(exception.getResponse().getEntity().getContent(), UTF_8)); | ||
| assertThat( | ||
| response, | ||
| both(not(containsString(sourceEscaped))).and( | ||
| containsString("REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled)") | ||
| ) | ||
| ); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.