diff --git a/plugins/ingest/src/main/java/org/elasticsearch/ingest/IngestDocument.java b/plugins/ingest/src/main/java/org/elasticsearch/ingest/IngestDocument.java index 7a695ce416b..ca4d55ee2db 100644 --- a/plugins/ingest/src/main/java/org/elasticsearch/ingest/IngestDocument.java +++ b/plugins/ingest/src/main/java/org/elasticsearch/ingest/IngestDocument.java @@ -467,12 +467,12 @@ public final class IngestDocument { newPath = path.substring(8, path.length()); } else { initialContext = sourceAndMetadata; - newPath = path; + if (path.startsWith("_source.")) { + newPath = path.substring(8, path.length()); + } else { + newPath = path; + } } - if (newPath.startsWith("_source.")) { - newPath = newPath.substring(8, path.length()); - } - this.pathElements = Strings.splitStringToArray(newPath, '.'); if (pathElements.length == 0) { throw new IllegalArgumentException("path [" + path + "] is not valid"); diff --git a/plugins/ingest/src/test/java/org/elasticsearch/ingest/IngestDocumentTests.java b/plugins/ingest/src/test/java/org/elasticsearch/ingest/IngestDocumentTests.java index 7d9bd58dc79..11ac560fb3e 100644 --- a/plugins/ingest/src/test/java/org/elasticsearch/ingest/IngestDocumentTests.java +++ b/plugins/ingest/src/test/java/org/elasticsearch/ingest/IngestDocumentTests.java @@ -366,6 +366,12 @@ public class IngestDocumentTests extends ESTestCase { assertThat(ingestDocument.getSourceAndMetadata().get("_ingest"), equalTo("value")); } + public void testSetIngestSourceObject() { + //test that we don't strip out the _source prefix when _ingest is used + ingestDocument.setFieldValue("_ingest._source", "value"); + assertThat(ingestDocument.getIngestMetadata().get("_source"), equalTo("value")); + } + public void testSetEmptyPathAfterStrippingOutPrefix() { try { ingestDocument.setFieldValue("_source.", "value");