模拟管道 API
编辑模拟管道 API编辑
针对一组提供的文档执行摄取管道。
POST /_ingest/pipeline/my-pipeline-id/_simulate { "docs": [ { "_index": "index", "_id": "id", "_source": { "foo": "bar" } }, { "_index": "index", "_id": "id", "_source": { "foo": "rab" } } ] }
请求编辑
POST /_ingest/pipeline/<pipeline>/_simulate
GET /_ingest/pipeline/<pipeline>/_simulate
POST /_ingest/pipeline/_simulate
GET /_ingest/pipeline/_simulate
先决条件编辑
- 如果启用了 Elasticsearch 安全功能,则您必须具有
read_pipeline
、manage_pipeline
、manage_ingest_pipelines
或manage
集群权限 才能使用此 API。
路径参数编辑
-
<pipeline>
- (必填*,字符串)要测试的管道。如果未在请求正文中指定
pipeline
,则此参数是必需的。
查询参数编辑
-
verbose
- (可选,布尔值)如果为
true
,则响应将包含已执行管道中每个处理器的输出数据。
请求正文编辑
-
pipeline
-
(必填*,对象)要测试的管道。如果未指定
<pipeline>
请求路径参数,则此参数是必需的。如果同时指定了此参数和请求路径参数,则 API 仅使用请求路径参数。pipeline
的属性-
description
- (可选,字符串)摄取管道的描述。
-
on_failure
-
(可选,处理器 对象数组)在处理器失败后立即运行的处理器。
每个处理器都支持处理器级别的
on_failure
值。如果没有on_failure
值的处理器失败,Elasticsearch 会使用此管道级别的参数作为回退。此参数中的处理器按指定的顺序依次运行。Elasticsearch 不会尝试运行管道中剩余的处理器。 -
processors
- (必填,处理器 对象数组)用于在索引文档之前对其执行转换的处理器。处理器按指定的顺序依次运行。
-
version
-
(可选,整数)外部系统用于跟踪摄取管道的版本号。
有关如何使用 version 属性,请参阅上面的
if_version
参数。 -
_meta
- (可选,对象)有关摄取管道的可选元数据。可以有任何内容。此映射不是由 Elasticsearch 自动生成的。
-
deprecated
- (可选,布尔值)将此摄取管道标记为已弃用。当在创建或更新非弃用索引模板时,将已弃用的摄取管道引用为默认或最终管道时,Elasticsearch 将发出弃用警告。
-
-
docs
-
(必填,对象数组)要在管道中测试的示例文档。
docs
对象的属性-
_id
- (可选,字符串)文档的唯一标识符。此 ID 在
_index
中必须是唯一的。 -
_index
- (可选,字符串)包含文档的索引的名称。
-
_routing
- (可选,字符串)用于将文档发送到特定主分片的值。请参阅
_routing
字段。 -
_source
- (必填,对象)文档的 JSON 正文。
-
示例编辑
将管道指定为路径参数编辑
POST /_ingest/pipeline/my-pipeline-id/_simulate { "docs": [ { "_index": "index", "_id": "id", "_source": { "foo": "bar" } }, { "_index": "index", "_id": "id", "_source": { "foo": "rab" } } ] }
API 返回以下响应
{ "docs": [ { "doc": { "_id": "id", "_index": "index", "_version": "-3", "_source": { "field2": "_value", "foo": "bar" }, "_ingest": { "timestamp": "2017-05-04T22:30:03.187Z" } } }, { "doc": { "_id": "id", "_index": "index", "_version": "-3", "_source": { "field2": "_value", "foo": "rab" }, "_ingest": { "timestamp": "2017-05-04T22:30:03.188Z" } } } ] }
在请求正文中指定管道编辑
response = client.ingest.simulate( body: { pipeline: { description: '_description', processors: [ { set: { field: 'field2', value: '_value' } } ] }, docs: [ { _index: 'index', _id: 'id', _source: { foo: 'bar' } }, { _index: 'index', _id: 'id', _source: { foo: 'rab' } } ] } ) puts response
POST /_ingest/pipeline/_simulate { "pipeline" : { "description": "_description", "processors": [ { "set" : { "field" : "field2", "value" : "_value" } } ] }, "docs": [ { "_index": "index", "_id": "id", "_source": { "foo": "bar" } }, { "_index": "index", "_id": "id", "_source": { "foo": "rab" } } ] }
API 返回以下响应
{ "docs": [ { "doc": { "_id": "id", "_index": "index", "_version": "-3", "_source": { "field2": "_value", "foo": "bar" }, "_ingest": { "timestamp": "2017-05-04T22:30:03.187Z" } } }, { "doc": { "_id": "id", "_index": "index", "_version": "-3", "_source": { "field2": "_value", "foo": "rab" }, "_ingest": { "timestamp": "2017-05-04T22:30:03.188Z" } } } ] }
查看详细结果编辑
您可以使用模拟管道 API 来查看每个处理器在摄取文档通过管道时如何影响它。要查看模拟请求中每个处理器的中间结果,可以将 verbose
参数添加到请求中。
response = client.ingest.simulate( verbose: true, body: { pipeline: { description: '_description', processors: [ { set: { field: 'field2', value: '_value2' } }, { set: { field: 'field3', value: '_value3' } } ] }, docs: [ { _index: 'index', _id: 'id', _source: { foo: 'bar' } }, { _index: 'index', _id: 'id', _source: { foo: 'rab' } } ] } ) puts response
POST /_ingest/pipeline/_simulate?verbose=true { "pipeline" : { "description": "_description", "processors": [ { "set" : { "field" : "field2", "value" : "_value2" } }, { "set" : { "field" : "field3", "value" : "_value3" } } ] }, "docs": [ { "_index": "index", "_id": "id", "_source": { "foo": "bar" } }, { "_index": "index", "_id": "id", "_source": { "foo": "rab" } } ] }
API 返回以下响应
{ "docs" : [ { "processor_results" : [ { "processor_type" : "set", "status" : "success", "doc" : { "_index" : "index", "_id" : "id", "_version": "-3", "_source" : { "field2" : "_value2", "foo" : "bar" }, "_ingest" : { "pipeline" : "_simulate_pipeline", "timestamp" : "2020-07-30T01:21:24.251836Z" } } }, { "processor_type" : "set", "status" : "success", "doc" : { "_index" : "index", "_id" : "id", "_version": "-3", "_source" : { "field3" : "_value3", "field2" : "_value2", "foo" : "bar" }, "_ingest" : { "pipeline" : "_simulate_pipeline", "timestamp" : "2020-07-30T01:21:24.251836Z" } } } ] }, { "processor_results" : [ { "processor_type" : "set", "status" : "success", "doc" : { "_index" : "index", "_id" : "id", "_version": "-3", "_source" : { "field2" : "_value2", "foo" : "rab" }, "_ingest" : { "pipeline" : "_simulate_pipeline", "timestamp" : "2020-07-30T01:21:24.251863Z" } } }, { "processor_type" : "set", "status" : "success", "doc" : { "_index" : "index", "_id" : "id", "_version": "-3", "_source" : { "field3" : "_value3", "field2" : "_value2", "foo" : "rab" }, "_ingest" : { "pipeline" : "_simulate_pipeline", "timestamp" : "2020-07-30T01:21:24.251863Z" } } } ] } ] }