From 9d5ca6aa772bd96948ce013746cdd33a6b64919e Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Thu, 10 Dec 2020 11:41:23 +0000 Subject: [PATCH] Add some more tests for source-only fields (#66030) This commit adds some more test coverage for runtime fields: * source-only field tests now use dynamic:false instead of defining disabled object fields * new tests for source-only fields defined at query time * tests for shadowing of nested fields --- .../index/mapper/DocumentParserTests.java | 37 ++++ .../101_geo_point_from_source.yml | 4 +- .../102_geo_point_source_in_query.yml | 160 ++++++++++++++++++ .../runtime_fields/11_keyword_from_source.yml | 4 +- .../12_keyword_source_in_query.yml | 64 +++++++ .../150_nested_runtime_fields.yml | 55 ++++++ .../runtime_fields/21_long_from_source.yml | 4 +- .../22_long_source_in_query.yml | 54 ++++++ .../runtime_fields/31_double_from_source.yml | 4 +- .../32_double_source_in_query.yml | 54 ++++++ .../runtime_fields/41_date_from_source.yml | 4 +- .../42_date_source_in_query.yml | 56 ++++++ .../test/runtime_fields/51_ip_from_source.yml | 4 +- .../runtime_fields/52_ip_source_in_query.yml | 54 ++++++ .../runtime_fields/61_boolean_from_source.yml | 4 +- .../62_boolean_source_in_query.yml | 63 +++++++ 16 files changed, 604 insertions(+), 21 deletions(-) create mode 100644 x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/102_geo_point_source_in_query.yml create mode 100644 x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/12_keyword_source_in_query.yml create mode 100644 x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/150_nested_runtime_fields.yml create mode 100644 x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/22_long_source_in_query.yml create mode 100644 x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/32_double_source_in_query.yml create mode 100644 x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/42_date_source_in_query.yml create mode 100644 x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/52_ip_source_in_query.yml create mode 100644 x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/62_boolean_source_in_query.yml diff --git a/server/src/test/java/org/elasticsearch/index/mapper/DocumentParserTests.java b/server/src/test/java/org/elasticsearch/index/mapper/DocumentParserTests.java index f6f5e0e49045..6039aeffeb7d 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/DocumentParserTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/DocumentParserTests.java @@ -146,6 +146,43 @@ public void testParseWithShadowedMultiField() throws Exception { assertNotNull(doc.rootDoc().getField("field.keyword")); } + public void testParseWithShadowedNestedField() throws Exception { + DocumentMapper mapper = createDocumentMapper(topMapping(b -> { + b.field("dynamic", "true"); + b.startObject("runtime"); + { + b.startObject("child.name").field("type", "keyword").endObject(); + } + b.endObject(); + b.startObject("properties"); + { + b.startObject("child"); + { + b.field("type", "nested"); + } + b.endObject(); + } + b.endObject(); + })); + + ParsedDocument doc = mapper.parse(source(b -> { + b.field("name", "alice"); + b.field("age", 42); + b.startArray("child"); + { + b.startObject().field("name", "bob").field("age", 12).endObject(); + b.startObject().field("name", "charlie").field("age", 10).endObject(); + } + b.endArray(); + })); + assertEquals(3, doc.docs().size()); + assertEquals("alice", doc.rootDoc().getField("name").stringValue()); + assertNull(doc.docs().get(0).getField("child.name")); // shadowed by the runtime field + assertEquals(12L, doc.docs().get(0).getField("child.age").numericValue()); + assertNull(doc.docs().get(1).getField("child.name")); + assertEquals(10L, doc.docs().get(1).getField("child.age").numericValue()); + } + public void testRuntimeFieldAndArrayChildren() throws IOException { DocumentMapper mapper = createDocumentMapper(topMapping(b -> { b.field("dynamic", "true"); diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/101_geo_point_from_source.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/101_geo_point_from_source.yml index 6e7f5c75b9d4..ae764c636e8c 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/101_geo_point_from_source.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/101_geo_point_from_source.yml @@ -8,15 +8,13 @@ setup: number_of_shards: 1 number_of_replicas: 0 mappings: + dynamic: false runtime: location: type: geo_point properties: timestamp: type: date - location: - type: object - enabled: false - do: bulk: diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/102_geo_point_source_in_query.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/102_geo_point_source_in_query.yml new file mode 100644 index 000000000000..7cb5f20178c0 --- /dev/null +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/102_geo_point_source_in_query.yml @@ -0,0 +1,160 @@ +--- +setup: + - do: + indices.create: + index: locations + body: + settings: + number_of_shards: 1 + number_of_replicas: 0 + mappings: + dynamic: false + properties: + timestamp: + type: date + + - do: + bulk: + index: locations + refresh: true + body: | + {"index":{}} + {"timestamp": "1998-04-30T14:30:17-05:00", "location" : {"lat": 13.5, "lon" : 34.89}} + {"index":{}} + {"timestamp": "1998-04-30T14:30:53-05:00", "location" : {"lat": -7.9, "lon" : 120.78}} + {"index":{}} + {"timestamp": "1998-04-30T14:31:12-05:00", "location" : {"lat": 45.78, "lon" : -173.45}} + {"index":{}} + {"timestamp": "1998-04-30T14:31:19-05:00", "location" : {"lat": 32.45, "lon" : 45.6}} + {"index":{}} + {"timestamp": "1998-04-30T14:31:22-05:00", "location" : {"lat": -63.24, "lon" : 31.0}} + {"index":{}} + {"timestamp": "1998-04-30T14:31:27-05:00", "location" : {"lat": 0.0, "lon" : 0.0}} + + +--- +"fetch fields from source": + - do: + search: + index: locations + body: + runtime_mappings: + location: + type: geo_point + sort: timestamp + fields: [location] + - match: {hits.total.value: 6} + - match: {hits.hits.0.fields.location: ["13.499999991618097, 34.889999935403466"] } + +--- +"exists query": + - do: + search: + index: locations + body: + runtime_mappings: + location: + type: geo_point + query: + exists: + field: location + - match: {hits.total.value: 6} + +--- +"geo bounding box query": + - do: + search: + index: locations + body: + runtime_mappings: + location: + type: geo_point + query: + geo_bounding_box: + location: + top_left: + lat: 10 + lon: -10 + bottom_right: + lat: -10 + lon: 10 + - match: {hits.total.value: 1} + +--- +"geo shape query": + - do: + search: + index: locations + body: + runtime_mappings: + location: + type: geo_point + query: + geo_shape: + location: + shape: + type: "envelope" + coordinates: [ [ -10, 10 ], [ 10, -10 ] ] + - match: {hits.total.value: 1} + +--- +"geo distance query": + - do: + search: + index: locations + body: + runtime_mappings: + location: + type: geo_point + query: + geo_distance: + distance: "2000km" + location: + lat: 0 + lon: 0 + - match: {hits.total.value: 1} + +--- +"bounds agg": + - do: + search: + index: locations + body: + runtime_mappings: + location: + type: geo_point + aggs: + bounds: + geo_bounds: + field: "location" + wrap_longitude: false + - match: {hits.total.value: 6} + - match: {aggregations.bounds.bounds.top_left.lat: 45.7799999602139 } + - match: {aggregations.bounds.bounds.top_left.lon: -173.4500000718981 } + - match: {aggregations.bounds.bounds.bottom_right.lat: -63.240000014193356 } + - match: {aggregations.bounds.bounds.bottom_right.lon: 120.77999993227422 } + +--- +"geo_distance sort": + - do: + search: + index: locations + body: + runtime_mappings: + location: + type: geo_point + sort: + _geo_distance: + location: + lat: 0.0 + lon: 0.0 + - match: {hits.total.value: 6} + - match: {hits.hits.0._source.location.lat: 0.0 } + - match: {hits.hits.0._source.location.lon: 0.0 } + - match: {hits.hits.1._source.location.lat: 13.5 } + - match: {hits.hits.1._source.location.lon: 34.89 } + - match: {hits.hits.2._source.location.lat: 32.45 } + - match: {hits.hits.2._source.location.lon: 45.6 } + - match: {hits.hits.3._source.location.lat: -63.24 } + - match: {hits.hits.3._source.location.lon: 31.0 } + diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/11_keyword_from_source.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/11_keyword_from_source.yml index 9219719e0443..781309869616 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/11_keyword_from_source.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/11_keyword_from_source.yml @@ -8,6 +8,7 @@ setup: number_of_shards: 1 number_of_replicas: 0 mappings: + dynamic: false runtime: status.active: type: keyword @@ -20,9 +21,6 @@ setup: type: double node: type: keyword - status: - type: object - enabled: false - do: diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/12_keyword_source_in_query.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/12_keyword_source_in_query.yml new file mode 100644 index 000000000000..eafa5624bd99 --- /dev/null +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/12_keyword_source_in_query.yml @@ -0,0 +1,64 @@ +--- +setup: + - do: + indices.create: + index: sensor + body: + settings: + number_of_shards: 1 + number_of_replicas: 0 + mappings: + dynamic: false + properties: + timestamp: + type: date + temperature: + type: long + voltage: + type: double + node: + type: keyword + + + - do: + bulk: + index: sensor + refresh: true + body: | + {"index":{}} + {"timestamp": 1516729294000, "temperature": 200, "voltage": 5.2, "node": "a", "status" : { "active" : "on" } } + {"index":{}} + {"timestamp": 1516642894000, "temperature": 201, "voltage": 5.8, "node": "b", "status" : [ { "active" : "on" } ] } + {"index":{}} + {"timestamp": 1516556494000, "temperature": 202, "voltage": 5.1, "node": "a", "status" : { "active" : [ "active", "on", true ] } } + {"index":{}} + {"timestamp": 1516470094000, "temperature": 198, "voltage": 5.6, "node": "b", "status" : 14 } + {"index":{}} + {"timestamp": 1516383694000, "temperature": 200, "voltage": 4.2, "node": "c", "status" : [ 9, null, { "active" : "off" } ] } + {"index":{}} + {"timestamp": 1516297294000, "temperature": 202, "voltage": 4.0, "node": "c", "status" : { "active" : "off" } } + +--- +"test matching": + - do: + search: + index: sensor + body: + runtime_mappings: + status.active: + type: keyword + query: + term: + status.active: "on" + - match: { hits.total.value: 3 } + - do: + search: + index: sensor + body: + runtime_mappings: + status.active: + type: keyword + query: + term: + status.active: "off" + - match: { hits.total.value: 2 } diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/150_nested_runtime_fields.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/150_nested_runtime_fields.yml new file mode 100644 index 000000000000..b4dd60e77c5b --- /dev/null +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/150_nested_runtime_fields.yml @@ -0,0 +1,55 @@ +--- +setup: + - do: + indices.create: + index: products + body: + settings: + number_of_shards: 1 + number_of_replicas: 0 + mappings: + properties: + name: + type: keyword + resellers: + type: nested + properties: + reseller: + type: keyword + + - do: + bulk: + index: products + refresh: true + body: | + {"index":{}} + {"name":"LED TV","resellers":[{"reseller":"companyA","price":350},{"reseller":"companyB","price":500}]} + +--- +"test docvalue loading": + - do: + search: + index: products + body: + runtime_mappings: + "resellers.price_with_vat": + type: double + script: | + for (double v : doc['resellers.price']) { + emit(v * 1.2) + } + query: + match: + name: "LED TV" + aggs: + resellers: + nested: + path: resellers + aggs: + min_price: + min: + field: resellers.price_with_vat + + - match: { aggregations.resellers.doc_count: 2 } + - match: { aggregations.resellers.min_price.value: 420 } + diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/21_long_from_source.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/21_long_from_source.yml index 1b7ee9a33514..c6967fd1b6c6 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/21_long_from_source.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/21_long_from_source.yml @@ -8,6 +8,7 @@ setup: number_of_shards: 1 number_of_replicas: 0 mappings: + dynamic: false runtime: history.count: type: long @@ -20,9 +21,6 @@ setup: type: double node: type: keyword - history: - type: object - enabled: false - do: bulk: diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/22_long_source_in_query.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/22_long_source_in_query.yml new file mode 100644 index 000000000000..e87e85284a6a --- /dev/null +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/22_long_source_in_query.yml @@ -0,0 +1,54 @@ +--- +setup: + - do: + indices.create: + index: sensor + body: + settings: + number_of_shards: 1 + number_of_replicas: 0 + mappings: + dynamic: false + properties: + timestamp: + type: date + temperature: + type: long + voltage: + type: double + node: + type: keyword + + - do: + bulk: + index: sensor + refresh: true + body: | + {"index":{}} + {"timestamp": 1516729294000, "temperature": 200, "voltage": 5.2, "node": "a", "history" : { "count" : 10 } } + {"index":{}} + {"timestamp": 1516642894000, "temperature": 201, "voltage": 5.8, "node": "b", "history" : { "count" : [ 11.2 ] } } + {"index":{}} + {"timestamp": 1516556494000, "temperature": 202, "voltage": 5.1, "node": "a", "history" : [ { "count" : 12 }, "false", true ] } + {"index":{}} + {"timestamp": 1516470094000, "temperature": 198, "voltage": 5.6, "node": "b", "history" : { "count" : "13" } } + {"index":{}} + {"timestamp": 1516383694000, "temperature": 200, "voltage": 4.2, "node": "c", "history" : { "count" : [ 14.5, true, "manglewurzle" ] } } + {"index":{}} + {"timestamp": 1516297294000, "temperature": 202, "voltage": 4.0, "node": "c", "history" : { "count" : 20 } } + +--- +"test matching": + - do: + search: + index: sensor + body: + runtime_mappings: + history.count: + type: long + query: + range: + history.count: + gte: 10 + lte: 18 + - match: { hits.total.value: 5 } diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/31_double_from_source.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/31_double_from_source.yml index a6ef1f8c17ec..d41bf95476a0 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/31_double_from_source.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/31_double_from_source.yml @@ -8,6 +8,7 @@ setup: number_of_shards: 1 number_of_replicas: 0 mappings: + dynamic: false runtime: history.count: type: double @@ -20,9 +21,6 @@ setup: type: double node: type: keyword - history: - type: object - enabled: false - do: bulk: diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/32_double_source_in_query.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/32_double_source_in_query.yml new file mode 100644 index 000000000000..dc3ac62f8c44 --- /dev/null +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/32_double_source_in_query.yml @@ -0,0 +1,54 @@ +--- +setup: + - do: + indices.create: + index: sensor + body: + settings: + number_of_shards: 1 + number_of_replicas: 0 + mappings: + dynamic: false + properties: + timestamp: + type: date + temperature: + type: long + voltage: + type: double + node: + type: keyword + + - do: + bulk: + index: sensor + refresh: true + body: | + {"index":{}} + {"timestamp": 1516729294000, "temperature": 200, "voltage": 5.2, "node": "a", "history" : { "count" : 10 } } + {"index":{}} + {"timestamp": 1516642894000, "temperature": 201, "voltage": 5.8, "node": "b", "history" : { "count" : [ 11.2 ] } } + {"index":{}} + {"timestamp": 1516556494000, "temperature": 202, "voltage": 5.1, "node": "a", "history" : [ { "count" : 12 }, "false", true ] } + {"index":{}} + {"timestamp": 1516470094000, "temperature": 198, "voltage": 5.6, "node": "b", "history" : { } } + {"index":{}} + {"timestamp": 1516383694000, "temperature": 200, "voltage": 4.2, "node": "c", "history" : { "count" : [ 14.5, true, "manglewurzle" ] } } + {"index":{}} + {"timestamp": 1516297294000, "temperature": 202, "voltage": 4.0, "node": "c", "history" : { "count" : 20 } } + +--- +"test matching": + - do: + search: + index: sensor + body: + runtime_mappings: + history.count: + type: double + query: + range: + history.count: + gte: 10 + lte: 18 + - match: { hits.total.value: 4 } diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/41_date_from_source.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/41_date_from_source.yml index d9a38dfbbe5d..8b53c12e4bed 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/41_date_from_source.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/41_date_from_source.yml @@ -8,6 +8,7 @@ setup: number_of_shards: 1 number_of_replicas: 0 mappings: + dynamic: false runtime: history.installed: type: date @@ -21,9 +22,6 @@ setup: type: double node: type: keyword - history: - type: object - enabled: false - do: bulk: diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/42_date_source_in_query.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/42_date_source_in_query.yml new file mode 100644 index 000000000000..6f36ad118731 --- /dev/null +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/42_date_source_in_query.yml @@ -0,0 +1,56 @@ +--- +setup: + - do: + indices.create: + index: sensor + body: + settings: + number_of_shards: 1 + number_of_replicas: 0 + mappings: + dynamic: false + properties: + timestamp: + type: date + temperature: + type: long + voltage: + type: double + node: + type: keyword + + - do: + bulk: + index: sensor + refresh: true + body: | + {"index":{}} + {"timestamp": 1516729294000, "temperature": 200, "voltage": 5.2, "node": "a", "history" : { "installed" : "2020-11-10" } } + {"index":{}} + {"timestamp": 1516642894000, "temperature": 201, "voltage": 5.8, "node": "b", "history" : { "installed" : "2020-14-10" } } + {"index":{}} + {"timestamp": 1516556494000, "temperature": 202, "voltage": 5.1, "node": "a", "history" : { "installed" : [ "2020-11-10", 2020 ] } } + {"index":{}} + {"timestamp": 1516470094000, "temperature": 198, "voltage": 5.6, "node": "b", "history" : [ { "installed" : "2020-10-10" } ] } + {"index":{}} + {"timestamp": 1516383694000, "temperature": 200, "voltage": 4.2, "node": "c", "history" : { "installed" : "foo" } } + {"index":{}} + {"timestamp": 1516297294000, "temperature": 202, "voltage": 4.0, "node": "c", "history" : { "installed" : "2020-11-10" } } + +--- +"test matching": + - do: + search: + index: sensor + body: + runtime_mappings: + history.installed: + type: date + format: yyyy-MM-dd + query: + range: + history.installed: + gte: "2020-11-01" + lte: "2020-11-30" + format: "yyyy-MM-dd" + - match: { hits.total.value: 3 } diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/51_ip_from_source.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/51_ip_from_source.yml index d067b4759c52..0cb36e8f06d8 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/51_ip_from_source.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/51_ip_from_source.yml @@ -8,6 +8,7 @@ setup: number_of_shards: 1 number_of_replicas: 0 mappings: + dynamic: false runtime: host.ip: type: ip @@ -20,9 +21,6 @@ setup: type: double node: type: keyword - host: - type: object - enabled: false - do: bulk: diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/52_ip_source_in_query.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/52_ip_source_in_query.yml new file mode 100644 index 000000000000..483b1919bf91 --- /dev/null +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/52_ip_source_in_query.yml @@ -0,0 +1,54 @@ +--- +setup: + - do: + indices.create: + index: sensor + body: + settings: + number_of_shards: 1 + number_of_replicas: 0 + mappings: + dynamic: false + properties: + timestamp: + type: date + temperature: + type: long + voltage: + type: double + node: + type: keyword + + - do: + bulk: + index: sensor + refresh: true + body: | + {"index":{}} + {"timestamp": 1516729294000, "temperature": 200, "voltage": 5.2, "node": "a", "host" : { "ip" : "128.192.7.1" } } + {"index":{}} + {"timestamp": 1516642894000, "temperature": 201, "voltage": 5.8, "node": "b", "host" : [ { "ip" : "1288888.192.7.1" } ] } + {"index":{}} + {"timestamp": 1516556494000, "temperature": 202, "voltage": 5.1, "node": "a", "host" : { "ip" : [ "128.192.7.3" ] } } + {"index":{}} + {"timestamp": 1516470094000, "temperature": 198, "voltage": 5.6, "node": "b", "host" : { "ip" : "128.192.7.4" } } + {"index":{}} + {"timestamp": 1516383694000, "temperature": 200, "voltage": 4.2, "node": "c", "host" : { "ip" : 12819275 } } + {"index":{}} + {"timestamp": 1516297294000, "temperature": 202, "voltage": 4.0, "node": "c", "host" : { "ip" : "128.192.7.6" } } + +--- +"test matching": + - do: + search: + index: sensor + body: + runtime_mappings: + host.ip: + type: ip + query: + range: + host.ip: + gte: "128.192.7.1" + lte: "128.192.7.5" + - match: { hits.total.value: 3 } diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/61_boolean_from_source.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/61_boolean_from_source.yml index ad1cfdb836a0..10a155946d0f 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/61_boolean_from_source.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/61_boolean_from_source.yml @@ -8,6 +8,7 @@ setup: number_of_shards: 1 number_of_replicas: 0 mappings: + dynamic: false runtime: state.active: type: boolean @@ -20,9 +21,6 @@ setup: type: double node: type: keyword - state: - type: object - enabled: false - do: bulk: diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/62_boolean_source_in_query.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/62_boolean_source_in_query.yml new file mode 100644 index 000000000000..132b1d3f2ba0 --- /dev/null +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/runtime_fields/62_boolean_source_in_query.yml @@ -0,0 +1,63 @@ +--- +setup: + - do: + indices.create: + index: sensor + body: + settings: + number_of_shards: 1 + number_of_replicas: 0 + mappings: + dynamic: false + properties: + timestamp: + type: date + temperature: + type: long + voltage: + type: double + node: + type: keyword + + - do: + bulk: + index: sensor + refresh: true + body: | + {"index":{}} + {"timestamp": 1516729294000, "temperature": 200, "voltage": 5.2, "node": "a", "state" : { "active" : true } } + {"index":{}} + {"timestamp": 1516642894000, "temperature": 201, "voltage": 5.8, "node": "b", "state" : { "active" : [ true ] } } + {"index":{}} + {"timestamp": 1516556494000, "temperature": 202, "voltage": 5.1, "node": "a", "state" : { "active" : [ false, "false", true ] } } + {"index":{}} + {"timestamp": 1516470094000, "temperature": 198, "voltage": 5.6, "node": "b", "state" : { "active" : "wibble" } } + {"index":{}} + {"timestamp": 1516383694000, "temperature": 200, "voltage": 4.2, "node": "c", "state" : [ { "active" : 9 }, { "active" : [ true ] }, "manglewurzle" ] } + {"index":{}} + {"timestamp": 1516297294000, "temperature": 202, "voltage": 4.0, "node": "c", "state" : { "active" : "false" } } + +--- +"test matching": + - do: + search: + index: sensor + body: + runtime_mappings: + state.active: + type: boolean + query: + term: + state.active: false + - match: { hits.total.value: 2 } + - do: + search: + index: sensor + body: + runtime_mappings: + state.active: + type: boolean + query: + term: + state.active: true + - match: { hits.total.value: 4 }