Simulate Pipeline API
editSimulate Pipeline API
editSimulate Pipeline Request
editA SimulatePipelineRequest
requires a source and a XContentType
. The source consists
of the request body. See the docs
for more details on the request body.
String source = "{\"" + "pipeline\":{" + "\"description\":\"_description\"," + "\"processors\":[{\"set\":{\"field\":\"field2\",\"value\":\"_value\"}}]" + "}," + "\"docs\":[" + "{\"_index\":\"index\",\"_type\":\"_doc\",\"_id\":\"id\",\"_source\":{\"foo\":\"bar\"}}," + "{\"_index\":\"index\",\"_type\":\"_doc\",\"_id\":\"id\",\"_source\":{\"foo\":\"rab\"}}" + "]" + "}"; SimulatePipelineRequest request = new SimulatePipelineRequest( new BytesArray(source.getBytes(StandardCharsets.UTF_8)), XContentType.JSON );
Optional arguments
editThe following arguments can optionally be provided:
You can either specify an existing pipeline to execute against the provided documents, or supply a pipeline definition in the body of the request. This option sets the id for an existing pipeline. |
Synchronous Execution
editAsynchronous Execution
editThe asynchronous execution of a simulate pipeline request requires both the SimulatePipelineRequest
instance and an ActionListener
instance to be passed to the asynchronous
method:
The asynchronous method does not block and returns immediately. Once it is
completed the ActionListener
is called back using the onResponse
method
if the execution successfully completed or using the onFailure
method if
it failed.
A typical listener for SimulatePipelineResponse
looks like:
Simulate Pipeline Response
editThe returned SimulatePipelineResponse
allows to retrieve information about the executed
operation as follows:
for (SimulateDocumentResult result: response.getResults()) { if (request.isVerbose()) { assert result instanceof SimulateDocumentVerboseResult; SimulateDocumentVerboseResult verboseResult = (SimulateDocumentVerboseResult)result; for (SimulateProcessorResult processorResult: verboseResult.getProcessorResults()) { processorResult.getIngestDocument(); processorResult.getFailure(); } } else { assert result instanceof SimulateDocumentBaseResult; SimulateDocumentBaseResult baseResult = (SimulateDocumentBaseResult)result; baseResult.getIngestDocument(); baseResult.getFailure(); } }
Get results for each of the documents provided as instance of |
|
If the request was in verbose mode cast the response to |
|
Check the result after each processor is applied. |
|
Get the ingest document for the result obtained in 3. |
|
Or get the failure for the result obtained in 3. |
|
Get the result as |
|
Get the ingest document for the result obtained in 6. |
|
Or get the failure for the result obtained in 6. |