diff --git a/rest-api-spec/test/explain/10_source_filtering.yaml b/rest-api-spec/test/explain/10_source_filtering.yaml new file mode 100644 index 00000000000..ecdc7173dfa --- /dev/null +++ b/rest-api-spec/test/explain/10_source_filtering.yaml @@ -0,0 +1,45 @@ +--- +"Source filtering": + + - do: + index: + index: test_1 + type: test + id: 1 + body: { "include": { "field1" : "v1", "field2": "v2" }, "count": 1 } + - do: + indices.refresh: + index: test_1 + + - do: + explain: { index: test_1, type: test, id: 1, _source: false, body: { query: { match_all: {}} } } + - match: { _index: test_1 } + - match: { _type: test } + - match: { _id: 1 } + - is_false: get._source + + - do: + explain: { index: test_1, type: test, id: 1, _source: true, body: { query: { match_all: {}} } } + - match: { get._source.include.field1: v1 } + + - do: + explain: { index: test_1, type: test, id: 1, _source: include.field1, body: { query: { match_all: {}} } } + - match: { get._source.include.field1: v1 } + - is_false: get._source.include.field2 + + - do: + explain: { index: test_1, type: test, id: 1, _source_include: include.field1, body: { query: { match_all: {}} } } + - match: { get._source.include.field1: v1 } + - is_false: get._source.include.field2 + + - do: + explain: { index: test_1, type: test, id: 1, _source_include: "include.field1,include.field2", body: { query: { match_all: {}} } } + - match: { get._source.include.field1: v1 } + - match: { get._source.include.field2: v2 } + - is_false: get._source.count + + - do: + explain: { index: test_1, type: test, id: 1, _source_include: include, _source_exclude: "*.field2", body: { query: { match_all: {}} } } + - match: { get._source.include.field1: v1 } + - is_false: get._source.include.field2 + - is_false: get._source.count diff --git a/rest-api-spec/test/explain/TODO.txt b/rest-api-spec/test/explain/TODO.txt new file mode 100644 index 00000000000..2362d9df8d4 --- /dev/null +++ b/rest-api-spec/test/explain/TODO.txt @@ -0,0 +1,6 @@ +Tests missing for: + +- everything :) + + +# preference diff --git a/rest-api-spec/test/get/20_fields.yaml b/rest-api-spec/test/get/20_fields.yaml index 6d85c5d86f5..f143b13039f 100644 --- a/rest-api-spec/test/get/20_fields.yaml +++ b/rest-api-spec/test/get/20_fields.yaml @@ -20,6 +20,20 @@ - match: { fields.foo: bar } - is_false: _source + - do: + get: + index: test_1 + type: test + id: 1 + fields: foo + _source: true + + - match: { _index: test_1 } + - match: { _type: test } + - match: { _id: 1 } + - match: { fields.foo: bar } + - match: { _source.foo: bar } + - do: get: index: test_1 diff --git a/rest-api-spec/test/get/70_source_filtering.yaml b/rest-api-spec/test/get/70_source_filtering.yaml new file mode 100644 index 00000000000..ad0466f3a79 --- /dev/null +++ b/rest-api-spec/test/get/70_source_filtering.yaml @@ -0,0 +1,42 @@ +--- +"Source filtering": + + - do: + index: + index: test_1 + type: test + id: 1 + body: { "include": { "field1" : "v1", "field2": "v2" }, "count": 1 } + - do: + get: { index: test_1, type: test, id: 1, _source: false } + + - match: { _index: test_1 } + - match: { _type: test } + - match: { _id: 1 } + - is_false: _source + + - do: + get: { index: test_1, type: test, id: 1, _source: true } + - match: { _source.include.field1: v1 } + + - do: + get: { index: test_1, type: test, id: 1, _source: include.field1 } + - match: { _source.include.field1: v1 } + - is_false: _source.include.field2 + + - do: + get: { index: test_1, type: test, id: 1, _source_include: include.field1 } + - match: { _source.include.field1: v1 } + - is_false: _source.include.field2 + + - do: + get: { index: test_1, type: test, id: 1, _source_include: "include.field1,include.field2" } + - match: { _source.include.field1: v1 } + - match: { _source.include.field2: v2 } + - is_false: _source.count + + - do: + get: { index: test_1, type: test, id: 1, _source_include: include, _source_exclude: "*.field2" } + - match: { _source.include.field1: v1 } + - is_false: _source.include.field2 + - is_false: _source.count diff --git a/rest-api-spec/test/get_source/70_source_filtering.yaml b/rest-api-spec/test/get_source/70_source_filtering.yaml new file mode 100644 index 00000000000..10a5aead213 --- /dev/null +++ b/rest-api-spec/test/get_source/70_source_filtering.yaml @@ -0,0 +1,26 @@ +--- +"Source filtering": + + - do: + index: + index: test_1 + type: test + id: 1 + body: { "include": { "field1" : "v1", "field2": "v2" }, "count": 1 } + + - do: + get_source: { index: test_1, type: test, id: 1, include: include.field1 } + - match: { include.field1: v1 } + - is_false: include.field2 + + - do: + get_source: { index: test_1, type: test, id: 1, include: "include.field1,include.field2" } + - match: { include.field1: v1 } + - match: { include.field2: v2 } + - is_false: count + + - do: + get_source: { index: test_1, type: test, id: 1, include: include, exclude: "*.field2" } + - match: { include.field1: v1 } + - is_false: include.field2 + - is_false: count diff --git a/rest-api-spec/test/mget/70_source_filtering.yaml b/rest-api-spec/test/mget/70_source_filtering.yaml new file mode 100644 index 00000000000..715fb378f18 --- /dev/null +++ b/rest-api-spec/test/mget/70_source_filtering.yaml @@ -0,0 +1,99 @@ +--- +"Source filtering": + + - do: + index: + index: test_1 + type: test + id: 1 + body: { "include": { "field1" : "v1", "field2": "v2" }, "count": 1 } + - do: + index: + index: test_1 + type: test + id: 2 + body: { "include": { "field1" : "v1", "field2": "v2" }, "count": 1 } + - do: + mget: + body: > + { docs: + [ { _index: "test_1", _type: "test", _id: "1", _source: false }, + { _index: "test_1", _type: "test", _id: "2", _source: true } + ] + } + + - match: { docs.0._id: 1 } + - is_false: docs.0._source + - match: { docs.1._id: 2 } + - is_true: docs.1._source + + + - do: + mget: + body: + docs: + - { _index: "test_1", _type: "test", _id: "1", _source: include.field1 } + - { _index: "test_1", _type: "test", _id: "2", _source: [ include.field1 ] } + + - match: { docs.0._source: { include: { field1: v1 }} } + - match: { docs.1._source: { include: { field1: v1 }} } + + + - do: + mget: + body: + docs: + - { _index: "test_1", _type: "test", _id: "1", _source: { include: include.field1 } } + - { _index: "test_1", _type: "test", _id: "2", _source: { include: [ include.field1 ] } } + + - match: { docs.0._source: { include: { field1: v1 }} } + - match: { docs.1._source: { include: { field1: v1 }} } + + - do: + mget: + body: + docs: + - { _index: "test_1", _type: "test", _id: "1", _source: { include: [ include ], exclude: [ "*.field2" ] } } + + - match: { docs.0._source: { include: { field1: v1 }} } + + - do: + mget: + _source: false + index: test_1 + body: { ids: [ 1,2 ] } + - is_false: docs.0._source + - is_false: docs.1._source + + - do: + mget: + _source: true + index: test_1 + body: { ids: [ 1,2 ] } + - is_true: docs.0._source + - is_true: docs.1._source + + - do: + mget: + _source: include.field1 + index: test_1 + body: { ids: [ 1,2 ] } + - match: { docs.0._source: { include: { field1: v1 }} } + - match: { docs.1._source: { include: { field1: v1 }} } + + - do: + mget: + _source_include: "include.field1,count" + index: test_1 + body: { ids: [ 1,2 ] } + - match: { docs.0._source: { include: { field1: v1 }, count: 1} } + - match: { docs.1._source: { include: { field1: v1 }, count: 1} } + + - do: + mget: + _source_include: include + _source_exclude: "*.field2" + index: test_1 + body: { ids: [ 1,2 ] } + - match: { docs.0._source: { include: { field1: v1 } } } + - match: { docs.1._source: { include: { field1: v1 } } } diff --git a/rest-api-spec/test/search/10_source_filtering.yaml b/rest-api-spec/test/search/10_source_filtering.yaml new file mode 100644 index 00000000000..a078f89d1fd --- /dev/null +++ b/rest-api-spec/test/search/10_source_filtering.yaml @@ -0,0 +1,92 @@ +--- +"Source filtering": + + - do: + index: + index: test_1 + type: test + id: 1 + body: { "include": { "field1" : "v1", "field2": "v2" }, "count": 1 } + - do: + indices.refresh: + + + - do: + search: + # stringified for boolean value + body: "{ _source: true, query: { match_all: {} } }" + + - length: { hits.hits: 1 } + - match: { hits.hits.0._source.count: 1 } + + - do: { search: { body: "{ _source: false, query: { match_all: {} } }" } } + - length: { hits.hits: 1 } + - is_false: hits.hits.0._source + + - do: { search: { body: { query: { match_all: {} } } } } + - length: { hits.hits: 1 } + - match: { hits.hits.0._source.count: 1 } + + - do: { search: { body: { _source: include.field1, query: { match_all: {} } } } } + - match: { hits.hits.0._source.include.field1: v1 } + - is_false: hits.hits.0._source.include.field2 + + - do: { search: { _source_include: include.field1, body: { _source: include.field2, query: { match_all: {} } } } } + - match: { hits.hits.0._source.include.field1: v1 } + - is_false: hits.hits.0._source.include.field2 + + - do: { search: { _source_include: include.field1, body: { query: { match_all: {} } } } } + - match: { hits.hits.0._source.include.field1: v1 } + - is_false: hits.hits.0._source.include.field2 + + - do: { search: { _source_exclude: count, body: { query: { match_all: {} } } } } + - match: { hits.hits.0._source.include: { field1 : v1 , field2: v2 }} + - is_false: hits.hits.0._source.count + + + - do: + search: + body: + _source: [ include.field1, include.field2 ] + query: { match_all: {} } + - match: { hits.hits.0._source.include.field1: v1 } + - match: { hits.hits.0._source.include.field2: v2 } + - is_false: hits.hits.0._source.count + + - do: + search: + body: + _source: + include: [ include.field1, include.field2 ] + query: { match_all: {} } + - match: { hits.hits.0._source.include.field1: v1 } + - match: { hits.hits.0._source.include.field2: v2 } + - is_false: hits.hits.0._source.count + + - do: + search: + body: + _source: + includes: include + excludes: "*.field2" + query: { match_all: {} } + - match: { hits.hits.0._source.include.field1: v1 } + - is_false: hits.hits.0._source.include.field2 + + + - do: + search: + body: + fields: [ include.field2 ] + query: { match_all: {} } + - match: { hits.hits.0.fields: { include.field2 : v2 }} + - is_false: hits.hits.0._source + + - do: + search: + body: + fields: [ include.field2, _source ] + query: { match_all: {} } + - match: { hits.hits.0.fields: { include.field2 : v2 }} + - is_true: hits.hits.0._source +