From 8df9fc82d9ce708741e2ee15b2d13e59c73ef948 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Tue, 27 Oct 2015 15:34:54 +0700 Subject: [PATCH] added custom rest specs for index and bulk that support the ingest param and added rest tests that verify that the ingest param is working --- .../rest-api-spec/api/ingest.bulk.json | 56 +++++++++++++ .../rest-api-spec/api/ingest.index.json | 80 +++++++++++++++++++ .../rest-api-spec/test/ingest/20_crud.yaml | 2 +- .../test/ingest/30_simple_processor.yaml | 63 +++++++++++++++ 4 files changed, 200 insertions(+), 1 deletion(-) create mode 100644 plugins/ingest/src/test/resources/rest-api-spec/api/ingest.bulk.json create mode 100644 plugins/ingest/src/test/resources/rest-api-spec/api/ingest.index.json create mode 100644 plugins/ingest/src/test/resources/rest-api-spec/test/ingest/30_simple_processor.yaml diff --git a/plugins/ingest/src/test/resources/rest-api-spec/api/ingest.bulk.json b/plugins/ingest/src/test/resources/rest-api-spec/api/ingest.bulk.json new file mode 100644 index 00000000000..5a4c7a856b9 --- /dev/null +++ b/plugins/ingest/src/test/resources/rest-api-spec/api/ingest.bulk.json @@ -0,0 +1,56 @@ +{ + "ingest.bulk": { + "documentation": "Copied from bulk in core to add the pipeline parameter to rest spec", + "methods": ["POST", "PUT"], + "url": { + "path": "/_bulk", + "paths": ["/_bulk", "/{index}/_bulk", "/{index}/{type}/_bulk"], + "parts": { + "index": { + "type" : "string", + "description" : "Default index for items which don't provide one" + }, + "type": { + "type" : "string", + "description" : "Default document type for items which don't provide one" + } + }, + "params": { + "consistency": { + "type" : "enum", + "options" : ["one", "quorum", "all"], + "description" : "Explicit write consistency setting for the operation" + }, + "refresh": { + "type" : "boolean", + "description" : "Refresh the index after performing the operation" + }, + "routing": { + "type" : "string", + "description" : "Specific routing value" + }, + "timeout": { + "type" : "time", + "description" : "Explicit operation timeout" + }, + "type": { + "type" : "string", + "description" : "Default document type for items which don't provide one" + }, + "fields": { + "type": "list", + "description" : "Default comma-separated list of fields to return in the response for updates" + }, + "ingest" : { + "type" : "string", + "description" : "The pipeline id to preprocess incoming documents with" + } + } + }, + "body": { + "description" : "The operation definition and data (action-data pairs), separated by newlines", + "required" : true, + "serialize" : "bulk" + } + } +} diff --git a/plugins/ingest/src/test/resources/rest-api-spec/api/ingest.index.json b/plugins/ingest/src/test/resources/rest-api-spec/api/ingest.index.json new file mode 100644 index 00000000000..23d3337bf60 --- /dev/null +++ b/plugins/ingest/src/test/resources/rest-api-spec/api/ingest.index.json @@ -0,0 +1,80 @@ +{ + "ingest.index": { + "documentation": "Copied from index in core to add support for the pipeline parameter to rest spec", + "methods": ["POST", "PUT"], + "url": { + "path": "/{index}/{type}", + "paths": ["/{index}/{type}", "/{index}/{type}/{id}"], + "parts": { + "id": { + "type" : "string", + "description" : "Document ID" + }, + "index": { + "type" : "string", + "required" : true, + "description" : "The name of the index" + }, + "type": { + "type" : "string", + "required" : true, + "description" : "The type of the document" + } + }, + "params": { + "consistency": { + "type" : "enum", + "options" : ["one", "quorum", "all"], + "description" : "Explicit write consistency setting for the operation" + }, + "op_type": { + "type" : "enum", + "options" : ["index", "create"], + "default" : "index", + "description" : "Explicit operation type" + }, + "parent": { + "type" : "string", + "description" : "ID of the parent document" + }, + "refresh": { + "type" : "boolean", + "description" : "Refresh the index after performing the operation" + }, + "routing": { + "type" : "string", + "description" : "Specific routing value" + }, + "timeout": { + "type" : "time", + "description" : "Explicit operation timeout" + }, + "timestamp": { + "type" : "time", + "description" : "Explicit timestamp for the document" + }, + "ttl": { + "type" : "duration", + "description" : "Expiration time for the document" + }, + "version" : { + "type" : "number", + "description" : "Explicit version number for concurrency control" + }, + "version_type": { + "type" : "enum", + "options" : ["internal", "external", "external_gte", "force"], + "description" : "Specific version type" + }, + "ingest" : { + "type" : "string", + "description" : "The pipeline id to preprocess incoming documents with" + } + } + }, + "body": { + "description" : "The document", + "required" : true + } + } +} diff --git a/plugins/ingest/src/test/resources/rest-api-spec/test/ingest/20_crud.yaml b/plugins/ingest/src/test/resources/rest-api-spec/test/ingest/20_crud.yaml index ae076f3e34f..56e12cdd59b 100644 --- a/plugins/ingest/src/test/resources/rest-api-spec/test/ingest/20_crud.yaml +++ b/plugins/ingest/src/test/resources/rest-api-spec/test/ingest/20_crud.yaml @@ -14,7 +14,7 @@ { "simple" : { "path" : "field1", - "value" : "_value", + "expected_value" : "_value", "add_field" : "field2", "add_field_value" : "_value" } diff --git a/plugins/ingest/src/test/resources/rest-api-spec/test/ingest/30_simple_processor.yaml b/plugins/ingest/src/test/resources/rest-api-spec/test/ingest/30_simple_processor.yaml new file mode 100644 index 00000000000..cd7e45ca3ae --- /dev/null +++ b/plugins/ingest/src/test/resources/rest-api-spec/test/ingest/30_simple_processor.yaml @@ -0,0 +1,63 @@ +--- +"Test simple processor": + - do: + cluster.health: + wait_for_status: green + + - do: + ingest.put_pipeline: + id: "my_pipeline" + body: > + { + "description": "_description", + "processors": [ + { + "simple" : { + "path" : "field1", + "expected_value" : "_value", + "add_field" : "field2", + "add_field_value" : "_value" + } + } + ] + } + - match: { _id: "my_pipeline" } + + # Simulate a Thread.sleep(), because pipeline are updated in the background + - do: + catch: request_timeout + cluster.health: + wait_for_nodes: 99 + timeout: 2s + - match: { "timed_out": true } + + - do: + ingest.index: + index: test + type: test + id: 1 + ingest: "my_pipeline" + body: {field1: "_value"} + + - do: + get: + index: test + type: test + id: 1 + - match: { _source.field1: "_value" } + - match: { _source.field2: "_value" } + + - do: + ingest.bulk: + ingest: "my_pipeline" + body: + - '{ "index": { "_index": "test", "_type": "test", "_id": "2" } }' + - '{ "field1": "_value" }' + + - do: + get: + index: test + type: test + id: 2 + - match: { _source.field1: "_value" } + - match: { _source.field2: "_value" }