Search in sources :

Example 76 with IngestDocument

use of org.elasticsearch.ingest.IngestDocument in project elasticsearch by elastic.

the class SimulatePipelineRequest method parseWithPipelineId.

static Parsed parseWithPipelineId(String pipelineId, Map<String, Object> config, boolean verbose, PipelineStore pipelineStore) {
    if (pipelineId == null) {
        throw new IllegalArgumentException("param [pipeline] is null");
    }
    Pipeline pipeline = pipelineStore.get(pipelineId);
    if (pipeline == null) {
        throw new IllegalArgumentException("pipeline [" + pipelineId + "] does not exist");
    }
    List<IngestDocument> ingestDocumentList = parseDocs(config);
    return new Parsed(pipeline, ingestDocumentList, verbose);
}
Also used : IngestDocument(org.elasticsearch.ingest.IngestDocument) Pipeline(org.elasticsearch.ingest.Pipeline)

Example 77 with IngestDocument

use of org.elasticsearch.ingest.IngestDocument in project elasticsearch by elastic.

the class SimulatePipelineRequest method parse.

static Parsed parse(Map<String, Object> config, boolean verbose, PipelineStore pipelineStore) throws Exception {
    Map<String, Object> pipelineConfig = ConfigurationUtils.readMap(null, null, config, Fields.PIPELINE);
    Pipeline pipeline = PIPELINE_FACTORY.create(SIMULATED_PIPELINE_ID, pipelineConfig, pipelineStore.getProcessorFactories());
    List<IngestDocument> ingestDocumentList = parseDocs(config);
    return new Parsed(pipeline, ingestDocumentList, verbose);
}
Also used : IngestDocument(org.elasticsearch.ingest.IngestDocument) Pipeline(org.elasticsearch.ingest.Pipeline)

Example 78 with IngestDocument

use of org.elasticsearch.ingest.IngestDocument in project elasticsearch by elastic.

the class SimulatePipelineRequest method parseDocs.

private static List<IngestDocument> parseDocs(Map<String, Object> config) {
    List<Map<String, Object>> docs = ConfigurationUtils.readList(null, null, config, Fields.DOCS);
    List<IngestDocument> ingestDocumentList = new ArrayList<>();
    for (Map<String, Object> dataMap : docs) {
        Map<String, Object> document = ConfigurationUtils.readMap(null, null, dataMap, Fields.SOURCE);
        IngestDocument ingestDocument = new IngestDocument(ConfigurationUtils.readStringProperty(null, null, dataMap, MetaData.INDEX.getFieldName(), "_index"), ConfigurationUtils.readStringProperty(null, null, dataMap, MetaData.TYPE.getFieldName(), "_type"), ConfigurationUtils.readStringProperty(null, null, dataMap, MetaData.ID.getFieldName(), "_id"), ConfigurationUtils.readOptionalStringProperty(null, null, dataMap, MetaData.ROUTING.getFieldName()), ConfigurationUtils.readOptionalStringProperty(null, null, dataMap, MetaData.PARENT.getFieldName()), document);
        ingestDocumentList.add(ingestDocument);
    }
    return ingestDocumentList;
}
Also used : ArrayList(java.util.ArrayList) IngestDocument(org.elasticsearch.ingest.IngestDocument) Map(java.util.Map)

Example 79 with IngestDocument

use of org.elasticsearch.ingest.IngestDocument in project elasticsearch by elastic.

the class TrackingResultProcessor method execute.

@Override
public void execute(IngestDocument ingestDocument) throws Exception {
    try {
        actualProcessor.execute(ingestDocument);
        processorResultList.add(new SimulateProcessorResult(actualProcessor.getTag(), new IngestDocument(ingestDocument)));
    } catch (Exception e) {
        if (ignoreFailure) {
            processorResultList.add(new SimulateProcessorResult(actualProcessor.getTag(), new IngestDocument(ingestDocument), e));
        } else {
            processorResultList.add(new SimulateProcessorResult(actualProcessor.getTag(), e));
        }
        throw e;
    }
}
Also used : IngestDocument(org.elasticsearch.ingest.IngestDocument)

Example 80 with IngestDocument

use of org.elasticsearch.ingest.IngestDocument in project elasticsearch by elastic.

the class SimulateDocumentSimpleResultTests method testSerialization.

public void testSerialization() throws IOException {
    boolean isFailure = randomBoolean();
    SimulateDocumentBaseResult simulateDocumentBaseResult;
    if (isFailure) {
        simulateDocumentBaseResult = new SimulateDocumentBaseResult(new IllegalArgumentException("test"));
    } else {
        IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
        simulateDocumentBaseResult = new SimulateDocumentBaseResult(ingestDocument);
    }
    BytesStreamOutput out = new BytesStreamOutput();
    simulateDocumentBaseResult.writeTo(out);
    StreamInput streamInput = out.bytes().streamInput();
    SimulateDocumentBaseResult otherSimulateDocumentBaseResult = new SimulateDocumentBaseResult(streamInput);
    if (isFailure) {
        assertThat(otherSimulateDocumentBaseResult.getIngestDocument(), equalTo(simulateDocumentBaseResult.getIngestDocument()));
        assertThat(otherSimulateDocumentBaseResult.getFailure(), instanceOf(IllegalArgumentException.class));
        IllegalArgumentException e = (IllegalArgumentException) otherSimulateDocumentBaseResult.getFailure();
        assertThat(e.getMessage(), equalTo("test"));
    } else {
        assertIngestDocument(otherSimulateDocumentBaseResult.getIngestDocument(), simulateDocumentBaseResult.getIngestDocument());
    }
}
Also used : StreamInput(org.elasticsearch.common.io.stream.StreamInput) IngestDocumentMatcher.assertIngestDocument(org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.elasticsearch.ingest.IngestDocument) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput)

Aggregations

IngestDocument (org.elasticsearch.ingest.IngestDocument)170 IngestDocumentMatcher.assertIngestDocument (org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument)105 Processor (org.elasticsearch.ingest.Processor)97 Matchers.containsString (org.hamcrest.Matchers.containsString)57 HashMap (java.util.HashMap)52 ArrayList (java.util.ArrayList)33 List (java.util.List)27 Map (java.util.Map)22 InputStream (java.io.InputStream)12 GZIPInputStream (java.util.zip.GZIPInputStream)11 SortOrder (org.elasticsearch.ingest.common.SortProcessor.SortOrder)11 TestProcessor (org.elasticsearch.ingest.TestProcessor)9 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)7 IOException (java.io.IOException)6 CompoundProcessor (org.elasticsearch.ingest.CompoundProcessor)6 TestTemplateService (org.elasticsearch.ingest.TestTemplateService)6 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)4 StreamInput (org.elasticsearch.common.io.stream.StreamInput)4 Pipeline (org.elasticsearch.ingest.Pipeline)4 Type (org.elasticsearch.ingest.common.ConvertProcessor.Type)4