|
12 | 12 | import org.apache.lucene.util.RamUsageEstimator; |
13 | 13 | import org.elasticsearch.ElasticsearchException; |
14 | 14 | import org.elasticsearch.ElasticsearchGenerationException; |
| 15 | +import org.elasticsearch.ElasticsearchParseException; |
15 | 16 | import org.elasticsearch.TransportVersion; |
16 | 17 | import org.elasticsearch.TransportVersions; |
17 | 18 | import org.elasticsearch.action.ActionRequestValidationException; |
|
40 | 41 | import org.elasticsearch.index.shard.ShardId; |
41 | 42 | import org.elasticsearch.ingest.ESONSource; |
42 | 43 | import org.elasticsearch.ingest.ESONXContentSerializer; |
| 44 | +import org.elasticsearch.ingest.IngestDocument; |
43 | 45 | import org.elasticsearch.ingest.IngestService; |
| 46 | +import org.elasticsearch.ingest.MapStructuredSource; |
44 | 47 | import org.elasticsearch.xcontent.ToXContent; |
45 | 48 | import org.elasticsearch.xcontent.XContentBuilder; |
46 | 49 | import org.elasticsearch.xcontent.XContentFactory; |
@@ -434,10 +437,28 @@ public void setStructuredSource(ESONSource.ESONObject esonSource) { |
434 | 437 | } |
435 | 438 | } |
436 | 439 |
|
| 440 | + public void ensureStructureSource() { |
| 441 | + if (useStructuredSource == false) { |
| 442 | + this.useStructuredSource = true; |
| 443 | + ESONSource.Builder builder = new ESONSource.Builder((int) (source.length() * 0.70)); |
| 444 | + try { |
| 445 | + XContentParser parser = XContentHelper.createParser(XContentParserConfiguration.EMPTY, source, contentType); |
| 446 | + structuredSource = builder.parse(parser); |
| 447 | + } catch (IOException e) { |
| 448 | + throw new UncheckedIOException(e); |
| 449 | + } |
| 450 | + } |
| 451 | + |
| 452 | + } |
| 453 | + |
437 | 454 | public boolean isStructuredSource() { |
438 | 455 | return useStructuredSource; |
439 | 456 | } |
440 | 457 |
|
| 458 | + public ESONSource.ESONObject structuredSource() { |
| 459 | + return structuredSource; |
| 460 | + } |
| 461 | + |
441 | 462 | public Map<String, Object> sourceAsMap() { |
442 | 463 | if (useStructuredSource) { |
443 | 464 | assert structuredSource != null; |
@@ -564,13 +585,7 @@ public IndexRequest source(BytesReference source, XContentType xContentType) { |
564 | 585 | this.source = Objects.requireNonNull(source); |
565 | 586 | this.contentType = Objects.requireNonNull(xContentType); |
566 | 587 | if (useStructuredSource) { |
567 | | - ESONSource.Builder builder = new ESONSource.Builder((int) (source.length() * 0.70)); |
568 | | - try { |
569 | | - XContentParser parser = XContentHelper.createParser(XContentParserConfiguration.EMPTY, source, xContentType); |
570 | | - structuredSource = builder.parse(parser); |
571 | | - } catch (IOException e) { |
572 | | - throw new UncheckedIOException(e); |
573 | | - } |
| 588 | + ensureStructureSource(); |
574 | 589 | } |
575 | 590 | return this; |
576 | 591 | } |
|
0 commit comments