Skip to content

Commit 8a7a1d3

Browse files
committed
[API] Reimplement Tests - spatial/70_script_doc_values.yml manually
This test is very flaky and I reimplemented it with refresh:true, to see if it remains stable.
1 parent b70058e commit 8a7a1d3

File tree

2 files changed

+151
-0
lines changed

2 files changed

+151
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
require_relative '../platinum_helper'
19+
20+
describe 'Spatial API' do
21+
context 'script doc values tests' do
22+
index = 'geospatial_test'
23+
before(:all) do
24+
ADMIN_CLIENT.indices.create(
25+
index: index,
26+
body: {
27+
settings: { number_of_shards: 1},
28+
mappings: { properties: { geo_shape: { type: 'geo_shape' } } }
29+
}
30+
)
31+
ADMIN_CLIENT.index(
32+
index: index,
33+
id: '1',
34+
body: {
35+
geo_shape: 'POLYGON((24.04725 59.942,24.04825 59.94125,24.04875 59.94125,24.04875 59.94175,24.048 59.9425,24.0475 59.94275,24.0465 59.94225,24.046 59.94225,24.04575 59.9425,24.04525 59.94225,24.04725 59.942))'
36+
},
37+
refresh: true
38+
)
39+
ADMIN_CLIENT.indices.refresh
40+
end
41+
42+
after(:all) do
43+
ADMIN_CLIENT.indices.delete(index: index)
44+
end
45+
46+
it 'centroid' do
47+
response = ADMIN_CLIENT.search(
48+
rest_total_hits_as_int: true,
49+
body: {
50+
script_fields: { centroid: { script: { source: "doc['geo_shape'].getCentroid()" } } }
51+
}
52+
)
53+
expect(response['hits']['hits'].first['fields']['centroid'].first['lat']).to eq 59.942043484188616
54+
expect(response['hits']['hits'].first['fields']['centroid'].first['lon']).to eq 24.047588920220733
55+
end
56+
57+
it 'bounding box' do
58+
response = ADMIN_CLIENT.search(
59+
rest_total_hits_as_int: true,
60+
body: {
61+
script_fields: { bbox: { script: { source: "doc['geo_shape'].getBoundingBox()" } } }
62+
}
63+
)
64+
expect(response['hits']['hits'].first['fields']['bbox'].first['top_left']['lat']).to eq 59.942749994806945
65+
expect(response['hits']['hits'].first['fields']['bbox'].first['top_left']['lon']).to eq 24.045249950140715
66+
expect(response['hits']['hits'].first['fields']['bbox'].first['bottom_right']['lat']).to eq 59.94124996941537
67+
expect(response['hits']['hits'].first['fields']['bbox'].first['bottom_right']['lon']).to eq 24.048749981448054
68+
end
69+
70+
it 'label position' do
71+
response = ADMIN_CLIENT.search(
72+
rest_total_hits_as_int: true,
73+
body: {
74+
script_fields: { label_position: { script: { source: "doc['geo_shape'].getLabelPosition()" } } }
75+
}
76+
)
77+
expect(response['hits']['hits'].first['fields']['label_position'].first['lat']).to eq 59.942043484188616
78+
expect(response['hits']['hits'].first['fields']['label_position'].first['lon']).to eq 24.047588920220733
79+
end
80+
81+
it 'bounding box points' do
82+
response = ADMIN_CLIENT.search(
83+
rest_total_hits_as_int: true,
84+
body: {
85+
script_fields: {
86+
topLeft: { script: { source: "doc['geo_shape'].getBoundingBox().topLeft()" } },
87+
bottomRight: { script: { source: "doc['geo_shape'].getBoundingBox().bottomRight()" } }
88+
}
89+
}
90+
)
91+
expect(response['hits']['hits'].first['fields']['topLeft'].first['lat']).to eq 59.942749994806945
92+
expect(response['hits']['hits'].first['fields']['topLeft'].first['lon']).to eq 24.045249950140715
93+
expect(response['hits']['hits'].first['fields']['bottomRight'].first['lat']).to eq 59.94124996941537
94+
expect(response['hits']['hits'].first['fields']['bottomRight'].first['lon']).to eq 24.048749981448054
95+
end
96+
97+
it 'dimensional type' do
98+
response = ADMIN_CLIENT.search(
99+
rest_total_hits_as_int: true,
100+
body: {
101+
script_fields: { type: { script: { source: "doc['geo_shape'].getDimensionalType()" } } }
102+
}
103+
)
104+
expect(response['hits']['hits'].first['fields']['type'].first).to eq 2
105+
end
106+
107+
it 'geoshape value' do
108+
response = ADMIN_CLIENT.search(
109+
rest_total_hits_as_int: true,
110+
body: {
111+
script_fields: { type: { script: { source: "doc['geo_shape'].get(0)" } } }
112+
}
113+
)
114+
expect(response['hits']['hits'].first['fields']['type'].first).to eq '<unserializable>'
115+
116+
response = ADMIN_CLIENT.search(
117+
rest_total_hits_as_int: true,
118+
body: {
119+
script_fields: { type: { script: { source: "field('geo_shape').get(null)"} } }
120+
}
121+
)
122+
expect(response['hits']['hits'].first['fields']['type'].first).to eq '<unserializable>'
123+
124+
response = ADMIN_CLIENT.search(
125+
rest_total_hits_as_int: true,
126+
body: {
127+
script_fields: { type: { script: { source: "$('geo_shape', null)"} } }
128+
}
129+
)
130+
expect(response['hits']['hits'].first['fields']['type'].first).to eq '<unserializable>'
131+
end
132+
133+
it 'diagonal length' do
134+
response = ADMIN_CLIENT.search(
135+
rest_total_hits_as_int: true,
136+
body: {
137+
script_fields: {
138+
width: { script: { source: "doc['geo_shape'].getMercatorWidth()" } },
139+
height: { script: { source: "doc['geo_shape'].getMercatorHeight()" } }
140+
}
141+
}
142+
)
143+
expect(response['hits']['hits'].first['fields']['width'].first).to eq 389.62170283915475
144+
expect(response['hits']['hits'].first['fields']['height'].first).to eq 333.37976841442287
145+
end
146+
end
147+
end

elasticsearch-api/spec/rest_api/skipped_tests_platinum.yml

+4
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,7 @@
105105
-
106106
:file: 'api_key/60_admin_user.yml'
107107
:description: 'Test query api keys'
108+
109+
-
110+
:file: 'spatial/70_script_doc_values.yml'
111+
:description: '*'

0 commit comments

Comments
 (0)