|
12 | 12 | import org.elasticsearch.common.bytes.BytesReference; |
13 | 13 | import org.elasticsearch.common.xcontent.XContentHelper; |
14 | 14 | import org.elasticsearch.ingest.IngestDocument; |
| 15 | +import org.elasticsearch.ingest.IngestPipelineFieldAccessPattern; |
| 16 | +import org.elasticsearch.ingest.IngestPipelineTestUtils; |
15 | 17 | import org.elasticsearch.ingest.RandomDocumentPicks; |
16 | 18 | import org.elasticsearch.test.ESTestCase; |
17 | 19 | import org.elasticsearch.xcontent.XContentBuilder; |
@@ -166,6 +168,28 @@ public void testAddToRoot() throws Exception { |
166 | 168 | assertEquals("see", sourceAndMetadata.get("c")); |
167 | 169 | } |
168 | 170 |
|
| 171 | + public void testAddToRootNestedField() throws Exception { |
| 172 | + String processorTag = randomAlphaOfLength(3); |
| 173 | + String randomTargetField = randomAlphaOfLength(2); |
| 174 | + JsonProcessor jsonProcessor = new JsonProcessor(processorTag, null, "a.b", randomTargetField, true, REPLACE, false); |
| 175 | + |
| 176 | + String json = "{\"a\": 1, \"b\": 2}"; |
| 177 | + Map<String, Object> subfield = new HashMap<>(); |
| 178 | + subfield.put("b", json); |
| 179 | + |
| 180 | + Map<String, Object> document = new HashMap<>(); |
| 181 | + document.put("a", subfield); |
| 182 | + document.put("c", "see"); |
| 183 | + |
| 184 | + IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document); |
| 185 | + ingestDocument = IngestPipelineTestUtils.runWithRandomAccessPattern(ingestDocument, jsonProcessor); |
| 186 | + |
| 187 | + Map<String, Object> sourceAndMetadata = ingestDocument.getSourceAndMetadata(); |
| 188 | + assertEquals(1, sourceAndMetadata.get("a")); |
| 189 | + assertEquals(2, sourceAndMetadata.get("b")); |
| 190 | + assertEquals("see", sourceAndMetadata.get("c")); |
| 191 | + } |
| 192 | + |
169 | 193 | public void testDuplicateKeys() throws Exception { |
170 | 194 | String processorTag = randomAlphaOfLength(3); |
171 | 195 | JsonProcessor lenientJsonProcessor = new JsonProcessor(processorTag, null, "a", null, true, REPLACE, true); |
|
0 commit comments