# Simulate Pipeline API（模拟管道 API）

原文链接 : [https://www.elastic.co/guide/en/elasticsearch/reference/5.3/simulate-pipeline-api.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.3/simulate-pipeline-api.html)

译文链接 : [http://www.apache.wiki/pages/viewpage.action?pageId=9406138](http://www.apache.wiki/pages/viewpage.action?pageId=9406138)

贡献者 : [那伊抹微笑](/display/~wangyangting)，[ApacheCN](/display/~apachecn)，[Apache中文网](/display/~apachechina)

该 **Simulate** **Pipeline** **API**（模拟管道 **API**）针对 **request** **body**（请求正文）中提供的一组 **documents**（文档）执行指定的 **pipeline**（管道）。

您可以指定一个现有的 **pipeline**（管道）来执行提供的 **documents**（文档），也可以在 **request** **body**（请求正文）中提供 **pipeline** **definition**（管道定义）。

以下是 **request** **body** 中提供的 **pipeline** **definition**（管道定义）和 **simulate** **request**（模拟请求）的结构 : 

```
POST _ingest/pipeline/_simulate
{
  "pipeline" : {
    // pipeline definition here
  },
  "docs" : [
    { /** first document **/ },
    { /** second document **/ },
    // ...
  ]
}
```

以下是针对现有 **pipeline**（管道）的 **simulate** **request**（模拟请求）的结构 : 

```
POST _ingest/pipeline/my-pipeline-id/_simulate
{
  "docs" : [
    { /** first document **/ },
    { /** second document **/ },
    // ...
  ]
}
```

以下是 **request**（请求）中  **pipeline** **definition**（管道定义）的 **simulate** **request**（模拟请求）及其 **response**（响应）的示例 : 

```
curl -XPOST 'localhost:9200/_ingest/pipeline/_simulate?pretty' -H 'Content-Type: application/json' -d'
{
  "pipeline" :
  {
    "description": "_description",
    "processors": [
      {
        "set" : {
          "field" : "field2",
          "value" : "_value"
        }
      }
    ]
  },
  "docs": [
    {
      "_index": "index",
      "_type": "type",
      "_id": "id",
      "_source": {
        "foo": "bar"
      }
    },
    {
      "_index": "index",
      "_type": "type",
      "_id": "id",
      "_source": {
        "foo": "rab"
      }
    }
  ]
}
'
```

**Response**（响应）: 

```
{
   "docs": [
      {
         "doc": {
            "_id": "id",
            "_ttl": null,
            "_parent": null,
            "_index": "index",
            "_routing": null,
            "_type": "type",
            "_timestamp": null,
            "_source": {
               "field2": "_value",
               "foo": "bar"
            },
            "_ingest": {
               "timestamp": "2016-01-04T23:53:27.186+0000"
            }
         }
      },
      {
         "doc": {
            "_id": "id",
            "_ttl": null,
            "_parent": null,
            "_index": "index",
            "_routing": null,
            "_type": "type",
            "_timestamp": null,
            "_source": {
               "field2": "_value",
               "foo": "rab"
            },
            "_ingest": {
               "timestamp": "2016-01-04T23:53:27.186+0000"
            }
         }
      }
   ]
}
```

### Viewing Verbose Results

您可以使用 **simulate** **pipeline** **API**（模拟管道 **API**）来了解每个 **processor**（处理器）是如何来处理 **ingest** **document** 经过 **pipeline**（管道）时的细节的。要在 **simulate** **request**（模拟请求）中查看每个 **processor**（处理器）的中间结果，可以将该参数 **verbose **添加到 **request**（请求）中。

以下是一个 **verbose****request**（详细请求）及其 **response**（响应）的示例 : 

```
curl -XPOST 'localhost:9200/_ingest/pipeline/_simulate?verbose&pretty' -H 'Content-Type: application/json' -d'
{
  "pipeline" :
  {
    "description": "_description",
    "processors": [
      {
        "set" : {
          "field" : "field2",
          "value" : "_value2"
        }
      },
      {
        "set" : {
          "field" : "field3",
          "value" : "_value3"
        }
      }
    ]
  },
  "docs": [
    {
      "_index": "index",
      "_type": "type",
      "_id": "id",
      "_source": {
        "foo": "bar"
      }
    },
    {
      "_index": "index",
      "_type": "type",
      "_id": "id",
      "_source": {
        "foo": "rab"
      }
    }
  ]
}
'
```

**Response**（响应）: 

```
{
   "docs": [
      {
         "processor_results": [
            {
               "tag": "processor[set]-0",
               "doc": {
                  "_id": "id",
                  "_ttl": null,
                  "_parent": null,
                  "_index": "index",
                  "_routing": null,
                  "_type": "type",
                  "_timestamp": null,
                  "_source": {
                     "field2": "_value2",
                     "foo": "bar"
                  },
                  "_ingest": {
                     "timestamp": "2016-01-05T00:02:51.383+0000"
                  }
               }
            },
            {
               "tag": "processor[set]-1",
               "doc": {
                  "_id": "id",
                  "_ttl": null,
                  "_parent": null,
                  "_index": "index",
                  "_routing": null,
                  "_type": "type",
                  "_timestamp": null,
                  "_source": {
                     "field3": "_value3",
                     "field2": "_value2",
                     "foo": "bar"
                  },
                  "_ingest": {
                     "timestamp": "2016-01-05T00:02:51.383+0000"
                  }
               }
            }
         ]
      },
      {
         "processor_results": [
            {
               "tag": "processor[set]-0",
               "doc": {
                  "_id": "id",
                  "_ttl": null,
                  "_parent": null,
                  "_index": "index",
                  "_routing": null,
                  "_type": "type",
                  "_timestamp": null,
                  "_source": {
                     "field2": "_value2",
                     "foo": "rab"
                  },
                  "_ingest": {
                     "timestamp": "2016-01-05T00:02:51.384+0000"
                  }
               }
            },
            {
               "tag": "processor[set]-1",
               "doc": {
                  "_id": "id",
                  "_ttl": null,
                  "_parent": null,
                  "_index": "index",
                  "_routing": null,
                  "_type": "type",
                  "_timestamp": null,
                  "_source": {
                     "field3": "_value3",
                     "field2": "_value2",
                     "foo": "rab"
                  },
                  "_ingest": {
                     "timestamp": "2016-01-05T00:02:51.384+0000"
                  }
               }
            }
         ]
      }
   ]
}
```