Simulate Pipeline API(模拟管道 API)

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

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

贡献者 : 那伊抹微笑ApacheCNApache中文网

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

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

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

  1. POST _ingest/pipeline/_simulate
  2. {
  3. "pipeline" : {
  4. // pipeline definition here
  5. },
  6. "docs" : [
  7. { /** first document **/ },
  8. { /** second document **/ },
  9. // ...
  10. ]
  11. }

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

  1. POST _ingest/pipeline/my-pipeline-id/_simulate
  2. {
  3. "docs" : [
  4. { /** first document **/ },
  5. { /** second document **/ },
  6. // ...
  7. ]
  8. }

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

  1. curl -XPOST 'localhost:9200/_ingest/pipeline/_simulate?pretty' -H 'Content-Type: application/json' -d'
  2. {
  3. "pipeline" :
  4. {
  5. "description": "_description",
  6. "processors": [
  7. {
  8. "set" : {
  9. "field" : "field2",
  10. "value" : "_value"
  11. }
  12. }
  13. ]
  14. },
  15. "docs": [
  16. {
  17. "_index": "index",
  18. "_type": "type",
  19. "_id": "id",
  20. "_source": {
  21. "foo": "bar"
  22. }
  23. },
  24. {
  25. "_index": "index",
  26. "_type": "type",
  27. "_id": "id",
  28. "_source": {
  29. "foo": "rab"
  30. }
  31. }
  32. ]
  33. }
  34. '

Response(响应):

  1. {
  2. "docs": [
  3. {
  4. "doc": {
  5. "_id": "id",
  6. "_ttl": null,
  7. "_parent": null,
  8. "_index": "index",
  9. "_routing": null,
  10. "_type": "type",
  11. "_timestamp": null,
  12. "_source": {
  13. "field2": "_value",
  14. "foo": "bar"
  15. },
  16. "_ingest": {
  17. "timestamp": "2016-01-04T23:53:27.186+0000"
  18. }
  19. }
  20. },
  21. {
  22. "doc": {
  23. "_id": "id",
  24. "_ttl": null,
  25. "_parent": null,
  26. "_index": "index",
  27. "_routing": null,
  28. "_type": "type",
  29. "_timestamp": null,
  30. "_source": {
  31. "field2": "_value",
  32. "foo": "rab"
  33. },
  34. "_ingest": {
  35. "timestamp": "2016-01-04T23:53:27.186+0000"
  36. }
  37. }
  38. }
  39. ]
  40. }

Viewing Verbose Results

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

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

  1. curl -XPOST 'localhost:9200/_ingest/pipeline/_simulate?verbose&pretty' -H 'Content-Type: application/json' -d'
  2. {
  3. "pipeline" :
  4. {
  5. "description": "_description",
  6. "processors": [
  7. {
  8. "set" : {
  9. "field" : "field2",
  10. "value" : "_value2"
  11. }
  12. },
  13. {
  14. "set" : {
  15. "field" : "field3",
  16. "value" : "_value3"
  17. }
  18. }
  19. ]
  20. },
  21. "docs": [
  22. {
  23. "_index": "index",
  24. "_type": "type",
  25. "_id": "id",
  26. "_source": {
  27. "foo": "bar"
  28. }
  29. },
  30. {
  31. "_index": "index",
  32. "_type": "type",
  33. "_id": "id",
  34. "_source": {
  35. "foo": "rab"
  36. }
  37. }
  38. ]
  39. }
  40. '

Response(响应):

  1. {
  2. "docs": [
  3. {
  4. "processor_results": [
  5. {
  6. "tag": "processor[set]-0",
  7. "doc": {
  8. "_id": "id",
  9. "_ttl": null,
  10. "_parent": null,
  11. "_index": "index",
  12. "_routing": null,
  13. "_type": "type",
  14. "_timestamp": null,
  15. "_source": {
  16. "field2": "_value2",
  17. "foo": "bar"
  18. },
  19. "_ingest": {
  20. "timestamp": "2016-01-05T00:02:51.383+0000"
  21. }
  22. }
  23. },
  24. {
  25. "tag": "processor[set]-1",
  26. "doc": {
  27. "_id": "id",
  28. "_ttl": null,
  29. "_parent": null,
  30. "_index": "index",
  31. "_routing": null,
  32. "_type": "type",
  33. "_timestamp": null,
  34. "_source": {
  35. "field3": "_value3",
  36. "field2": "_value2",
  37. "foo": "bar"
  38. },
  39. "_ingest": {
  40. "timestamp": "2016-01-05T00:02:51.383+0000"
  41. }
  42. }
  43. }
  44. ]
  45. },
  46. {
  47. "processor_results": [
  48. {
  49. "tag": "processor[set]-0",
  50. "doc": {
  51. "_id": "id",
  52. "_ttl": null,
  53. "_parent": null,
  54. "_index": "index",
  55. "_routing": null,
  56. "_type": "type",
  57. "_timestamp": null,
  58. "_source": {
  59. "field2": "_value2",
  60. "foo": "rab"
  61. },
  62. "_ingest": {
  63. "timestamp": "2016-01-05T00:02:51.384+0000"
  64. }
  65. }
  66. },
  67. {
  68. "tag": "processor[set]-1",
  69. "doc": {
  70. "_id": "id",
  71. "_ttl": null,
  72. "_parent": null,
  73. "_index": "index",
  74. "_routing": null,
  75. "_type": "type",
  76. "_timestamp": null,
  77. "_source": {
  78. "field3": "_value3",
  79. "field2": "_value2",
  80. "foo": "rab"
  81. },
  82. "_ingest": {
  83. "timestamp": "2016-01-05T00:02:51.384+0000"
  84. }
  85. }
  86. }
  87. ]
  88. }
  89. ]
  90. }