Skip to content

Commit 07fed11

Browse files
committed
add more integ test for update mapping and fetch derived fields
Signed-off-by: Rishabh Maurya <[email protected]>
1 parent 1dd9df6 commit 07fed11

File tree

4 files changed

+796
-6
lines changed

4 files changed

+796
-6
lines changed
Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"derived_field using index mapping definition":
1+
"Test derived_field supported type using index mapping definition":
22
- skip:
33
version: " - 2.14.99"
44
reason: "derived_field feature was added in 2.15"
@@ -27,6 +27,8 @@
2727
type: ip
2828
boolean:
2929
type: boolean
30+
array_of_long:
31+
type: long
3032
json_field:
3133
type: text
3234
derived:
@@ -61,6 +63,9 @@
6163
derived_boolean:
6264
type: boolean
6365
script: "emit(params._source[\"boolean\"])"
66+
derived_array_of_long:
67+
type: long
68+
script: "emit(params._source[\"array_of_long\"][0]);emit(params._source[\"array_of_long\"][1]);"
6469
derived_object:
6570
type: object
6671
properties:
@@ -82,7 +87,8 @@
8287
geo: [0.0, 20.0],
8388
ip: "192.168.0.1",
8489
boolean: true,
85-
json_field: "{\"keyword\":\"json_keyword1\",\"long\":10,\"float\":10.0,\"double\":10.0,\"date\":\"2021-01-01T00:00:00Z\",\"ip\":\"10.0.0.1\",\"boolean\":true}"
90+
array_of_long: [1, 2],
91+
json_field: "{\"keyword\":\"json_keyword1\",\"long\":10,\"float\":10.0,\"double\":10.0,\"date\":\"2021-01-01T00:00:00Z\",\"ip\":\"10.0.0.1\",\"boolean\":true, \"array_of_long\": [1, 2]}}"
8692
}
8793

8894
- do:
@@ -99,7 +105,8 @@
99105
geo: [10.0, 30.0],
100106
ip: "192.168.0.2",
101107
boolean: false,
102-
json_field: "{\"keyword\":\"json_keyword2\",\"long\":20,\"float\":20.0,\"double\":20.0,\"date\":\"2021-02-01T00:00:00Z\",\"ip\":\"10.0.0.2\",\"boolean\":false}"
108+
array_of_long: [2, 3],
109+
json_field: "{\"keyword\":\"json_keyword2\",\"long\":20,\"float\":20.0,\"double\":20.0,\"date\":\"2021-02-01T00:00:00Z\",\"ip\":\"10.0.0.2\",\"boolean\":false, \"array_of_long\": [2, 3]}}"
103110
}
104111

105112
- do:
@@ -116,7 +123,8 @@
116123
geo: [20.0, 40.0],
117124
ip: "192.168.0.3",
118125
boolean: true,
119-
json_field: "{\"keyword\":\"json_keyword3\",\"long\":30,\"float\":30.0,\"double\":30.0,\"date\":\"2021-03-01T00:00:00Z\",\"ip\":\"10.0.0.3\",\"boolean\":true}"
126+
array_of_long: [3, 4],
127+
json_field: "{\"keyword\":\"json_keyword3\",\"long\":30,\"float\":30.0,\"double\":30.0,\"date\":\"2021-03-01T00:00:00Z\",\"ip\":\"10.0.0.3\",\"boolean\":true, \"array_of_long\": [3, 4]}"
120128
}
121129

122130
- do:
@@ -133,7 +141,8 @@
133141
geo: [30.0, 50.0],
134142
ip: "192.168.0.4",
135143
boolean: false,
136-
json_field: "{\"keyword\":\"json_keyword4\",\"long\":40,\"float\":40.0,\"double\":40.0,\"date\":\"2021-04-01T00:00:00Z\",\"ip\":\"10.0.0.4\",\"boolean\":false}"
144+
array_of_long: [4, 5],
145+
json_field: "{\"keyword\":\"json_keyword4\",\"long\":40,\"float\":40.0,\"double\":40.0,\"date\":\"2021-04-01T00:00:00Z\",\"ip\":\"10.0.0.4\",\"boolean\":false, \"array_of_long\": [4, 5]}"
137146
}
138147

139148
- do:
@@ -150,7 +159,8 @@
150159
geo: [40.0, 60.0],
151160
ip: "192.168.0.5",
152161
boolean: true,
153-
json_field: "{\"keyword\":\"json_keyword5\",\"long\":50,\"float\":50.0,\"double\":50.0,\"date\":\"2021-05-01T00:00:00Z\",\"ip\":\"10.0.0.5\",\"boolean\":true}"
162+
array_of_long: [5, 6],
163+
json_field: "{\"keyword\":\"json_keyword5\",\"long\":50,\"float\":50.0,\"double\":50.0,\"date\":\"2021-05-01T00:00:00Z\",\"ip\":\"10.0.0.5\",\"boolean\":true, \"array_of_long\": [5, 6]}"
154164
}
155165

156166
- do:
@@ -276,6 +286,19 @@
276286

277287
- match: { hits.total: 3 }
278288

289+
# Tests for derived_array_of_long
290+
- do:
291+
search:
292+
rest_total_hits_as_int: true
293+
index: test
294+
body:
295+
query:
296+
range:
297+
derived_array_of_long:
298+
gte: 3
299+
300+
- match: { hits.total: 4 }
301+
279302
# Tests for derived_object.keyword
280303
- do:
281304
search:
@@ -366,3 +389,16 @@
366389
value: true
367390

368391
- match: { hits.total: 3 }
392+
393+
# Tests for derived_object.array_of_long
394+
- do:
395+
search:
396+
rest_total_hits_as_int: true
397+
index: test
398+
body:
399+
query:
400+
range:
401+
derived_object.array_of_long:
402+
gte: 3
403+
404+
- match: { hits.total: 4 }
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
---
2+
"Test create and update mapping for derived fields":
3+
- skip:
4+
version: " - 2.14.99"
5+
reason: "derived_field feature was added in 2.15"
6+
- do:
7+
indices.create:
8+
index: test_index
9+
10+
- do:
11+
indices.put_mapping:
12+
index: test_index
13+
body:
14+
properties:
15+
text:
16+
type: text
17+
json_field:
18+
type: text
19+
derived:
20+
derived_text:
21+
type: text
22+
script: "emit(params._source[\"text\"])"
23+
derived_text_source_indexed_field:
24+
type: keyword
25+
script: "emit(params._source[\"text\"])"
26+
source_indexed_field: "text"
27+
derived_date:
28+
type: date
29+
script: "emit(params._source[\"keyword\"])"
30+
derived_object:
31+
type: object
32+
properties:
33+
keyword: keyword
34+
script: "emit(params._source[\"json_field\"])"
35+
source_indexed_field: "json_field"
36+
37+
- do:
38+
indices.get_mapping:
39+
index: test_index
40+
41+
- match: {test_index.mappings.derived.derived_text.type: text}
42+
- match: {test_index.mappings.derived.derived_text_source_indexed_field.type: keyword}
43+
- match: {test_index.mappings.derived.derived_text_source_indexed_field.source_indexed_field: text}
44+
- match: {test_index.mappings.derived.derived_date.type: date}
45+
- match: {test_index.mappings.derived.derived_object.type: object}
46+
- match: {test_index.mappings.derived.derived_object.properties.keyword: keyword}
47+
- match: {test_index.mappings.derived.derived_object.source_indexed_field: json_field}
48+
49+
50+
- do:
51+
indices.put_mapping:
52+
index: test_index
53+
body:
54+
properties:
55+
text:
56+
type: text
57+
json_field:
58+
type: text
59+
derived:
60+
derived_text:
61+
type: keyword
62+
script: "emit(params._source[\"text\"])"
63+
derived_text_source_indexed_field:
64+
type: text
65+
script: "emit(params._source[\"text\"])"
66+
source_indexed_field: "text"
67+
derived_date:
68+
type: keyword
69+
script: "emit(params._source[\"keyword\"])"
70+
derived_object:
71+
type: object
72+
properties:
73+
keyword: text
74+
script: "emit(params._source[\"text\"])"
75+
source_indexed_field: "text"
76+
format: "dd-MM-yyyy"
77+
ignore_malformed: true
78+
79+
- do:
80+
indices.get_mapping:
81+
index: test_index
82+
83+
- match: {test_index.mappings.derived.derived_text.type: keyword}
84+
- match: {test_index.mappings.derived.derived_text_source_indexed_field.type: text}
85+
- match: {test_index.mappings.derived.derived_text_source_indexed_field.source_indexed_field: text}
86+
- match: {test_index.mappings.derived.derived_date.type: keyword}
87+
- match: {test_index.mappings.derived.derived_object.type: object}
88+
- match: {test_index.mappings.derived.derived_object.properties.keyword: text}
89+
- match: {test_index.mappings.derived.derived_object.source_indexed_field: text}
90+
- match: {test_index.mappings.derived.derived_object.format: "dd-MM-yyyy"}
91+
- match: {test_index.mappings.derived.derived_object.ignore_malformed: true}
92+
93+
94+
- do:
95+
indices.put_mapping:
96+
index: test_index
97+
body:
98+
properties:
99+
text:
100+
type: text
101+
json_field:
102+
type: text
103+
derived:
104+
derived_object:
105+
type: object
106+
properties:
107+
keyword: keyword
108+
script: "emit(params._source[\"json_field\"])"
109+
source_indexed_field: "json_field"
110+
ignore_malformed: false
111+
112+
- do:
113+
indices.get_mapping:
114+
index: test_index
115+
116+
- match: {test_index.mappings.derived.derived_text.type: keyword}
117+
- match: {test_index.mappings.derived.derived_text_source_indexed_field.type: text}
118+
- match: {test_index.mappings.derived.derived_text_source_indexed_field.source_indexed_field: text}
119+
- match: {test_index.mappings.derived.derived_date.type: keyword}
120+
- match: {test_index.mappings.derived.derived_object.type: object}
121+
- match: {test_index.mappings.derived.derived_object.properties.keyword: keyword}
122+
- match: {test_index.mappings.derived.derived_object.source_indexed_field: json_field}
123+
- is_false: test_index.mappings.derived.derived_object.ignore_malformed

0 commit comments

Comments
 (0)