模拟管道 API
编辑模拟管道 API
编辑对一组提供的文档执行摄取管道。
resp = client.ingest.simulate( id="my-pipeline-id", docs=[ { "_index": "index", "_id": "id", "_source": { "foo": "bar" } }, { "_index": "index", "_id": "id", "_source": { "foo": "rab" } } ], ) print(resp)
const response = await client.ingest.simulate({ id: "my-pipeline-id", docs: [ { _index: "index", _id: "id", _source: { foo: "bar", }, }, { _index: "index", _id: "id", _source: { foo: "rab", }, }, ], }); console.log(response);
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
-
(可选,整数) 外部系统用于跟踪摄取管道的版本号。
有关版本属性的使用方式,请参阅上面的
if_version
参数。 -
_meta
- (可选,对象) 关于摄取管道的可选元数据。可以有任何内容。此映射不是由 Elasticsearch 自动生成的。
-
deprecated
- (可选,布尔值) 将此摄取管道标记为已弃用。当在创建或更新非已弃用索引模板时将已弃用摄取管道作为默认或最终管道引用时,Elasticsearch 将发出弃用警告。
-
-
docs
-
(必填,对象的数组) 要在管道中测试的示例文档。
docs
对象的属性-
_id
- (可选,字符串) 文档的唯一标识符。此 ID 必须在
_index
中唯一。 -
_index
- (可选,字符串) 包含文档的索引名称。
-
_routing
- (可选,字符串) 用于将文档发送到特定主分片的 value。请参阅
_routing
字段。 -
_source
- (必填,对象) 文档的 JSON 主体。
-
示例
编辑将管道指定为路径参数
编辑resp = client.ingest.simulate( id="my-pipeline-id", docs=[ { "_index": "index", "_id": "id", "_source": { "foo": "bar" } }, { "_index": "index", "_id": "id", "_source": { "foo": "rab" } } ], ) print(resp)
const response = await client.ingest.simulate({ id: "my-pipeline-id", docs: [ { _index: "index", _id: "id", _source: { foo: "bar", }, }, { _index: "index", _id: "id", _source: { foo: "rab", }, }, ], }); console.log(response);
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" } } } ] }
在请求正文中指定管道
编辑resp = client.ingest.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" } } ], ) print(resp)
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
const response = await client.ingest.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", }, }, ], }); console.log(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
参数。
resp = client.ingest.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" } } ], ) print(resp)
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
const response = await client.ingest.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", }, }, ], }); console.log(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" } } } ] } ] }