10
10
11
11
import org .elasticsearch .ingest .IngestDocument ;
12
12
import org .elasticsearch .ingest .Processor ;
13
+ import org .elasticsearch .ingest .TestIngestDocument ;
13
14
import org .elasticsearch .ingest .TestTemplateService ;
14
15
import org .elasticsearch .test .ESTestCase ;
15
16
@@ -25,15 +26,15 @@ public class DotExpanderProcessorTests extends ESTestCase {
25
26
public void testEscapeFields () throws Exception {
26
27
Map <String , Object > source = new HashMap <>();
27
28
source .put ("foo.bar" , "baz1" );
28
- IngestDocument document = new IngestDocument ( source , Collections . emptyMap () );
29
+ IngestDocument document = TestIngestDocument . ofSourceAndMetadata ( source );
29
30
DotExpanderProcessor processor = new DotExpanderProcessor ("_tag" , null , null , "foo.bar" );
30
31
processor .execute (document );
31
32
assertThat (document .getFieldValue ("foo" , Map .class ).size (), equalTo (1 ));
32
33
assertThat (document .getFieldValue ("foo.bar" , String .class ), equalTo ("baz1" ));
33
34
34
35
source = new HashMap <>();
35
36
source .put ("foo.bar.baz" , "value" );
36
- document = new IngestDocument ( source , Collections . emptyMap () );
37
+ document = TestIngestDocument . ofSourceAndMetadata ( source );
37
38
processor = new DotExpanderProcessor ("_tag" , null , null , "foo.bar.baz" );
38
39
processor .execute (document );
39
40
assertThat (document .getFieldValue ("foo" , Map .class ).size (), equalTo (1 ));
@@ -43,7 +44,7 @@ public void testEscapeFields() throws Exception {
43
44
source = new HashMap <>();
44
45
source .put ("foo.bar" , "baz1" );
45
46
source .put ("foo" , new HashMap <>(Collections .singletonMap ("bar" , "baz2" )));
46
- document = new IngestDocument ( source , Collections . emptyMap () );
47
+ document = TestIngestDocument . ofSourceAndMetadata ( source );
47
48
processor = new DotExpanderProcessor ("_tag" , null , null , "foo.bar" );
48
49
processor .execute (document );
49
50
assertThat (document .getSourceAndMetadata ().size (), equalTo (1 ));
@@ -54,7 +55,7 @@ public void testEscapeFields() throws Exception {
54
55
source = new HashMap <>();
55
56
source .put ("foo.bar" , "2" );
56
57
source .put ("foo" , new HashMap <>(Collections .singletonMap ("bar" , 1 )));
57
- document = new IngestDocument ( source , Collections . emptyMap () );
58
+ document = TestIngestDocument . ofSourceAndMetadata ( source );
58
59
processor = new DotExpanderProcessor ("_tag" , null , null , "foo.bar" );
59
60
processor .execute (document );
60
61
assertThat (document .getSourceAndMetadata ().size (), equalTo (1 ));
@@ -67,15 +68,15 @@ public void testEscapeFields_valueField() throws Exception {
67
68
Map <String , Object > source = new HashMap <>();
68
69
source .put ("foo.bar" , "baz1" );
69
70
source .put ("foo" , "baz2" );
70
- IngestDocument document1 = new IngestDocument ( source , Collections . emptyMap () );
71
+ IngestDocument document1 = TestIngestDocument . ofSourceAndMetadata ( source );
71
72
Processor processor1 = new DotExpanderProcessor ("_tag" , null , null , "foo.bar" );
72
73
// foo already exists and if a leaf field and therefor can't be replaced by a map field:
73
74
Exception e = expectThrows (IllegalArgumentException .class , () -> processor1 .execute (document1 ));
74
75
assertThat (e .getMessage (), equalTo ("cannot expand [foo.bar], because [foo] is not an object field, but a value field" ));
75
76
76
77
// so because foo is no branch field but a value field the `foo.bar` field can't be expanded
77
78
// into [foo].[bar], so foo should be renamed first into `[foo].[bar]:
78
- IngestDocument document = new IngestDocument ( source , Collections . emptyMap () );
79
+ IngestDocument document = TestIngestDocument . ofSourceAndMetadata ( source );
79
80
Processor processor = new RenameProcessor (
80
81
"_tag" ,
81
82
null ,
@@ -92,7 +93,7 @@ public void testEscapeFields_valueField() throws Exception {
92
93
93
94
source = new HashMap <>();
94
95
source .put ("foo.bar" , "baz1" );
95
- document = new IngestDocument ( source , Collections . emptyMap () );
96
+ document = TestIngestDocument . ofSourceAndMetadata ( source );
96
97
processor = new DotExpanderProcessor ("_tag" , null , null , "foo.bar" );
97
98
processor .execute (document );
98
99
assertThat (document .getFieldValue ("foo" , Map .class ).size (), equalTo (1 ));
@@ -101,7 +102,7 @@ public void testEscapeFields_valueField() throws Exception {
101
102
source = new HashMap <>();
102
103
source .put ("foo.bar.baz" , "baz1" );
103
104
source .put ("foo" , new HashMap <>(Collections .singletonMap ("bar" , new HashMap <>())));
104
- document = new IngestDocument ( source , Collections . emptyMap () );
105
+ document = TestIngestDocument . ofSourceAndMetadata ( source );
105
106
processor = new DotExpanderProcessor ("_tag" , null , null , "foo.bar.baz" );
106
107
processor .execute (document );
107
108
assertThat (document .getFieldValue ("foo" , Map .class ).size (), equalTo (1 ));
@@ -111,7 +112,7 @@ public void testEscapeFields_valueField() throws Exception {
111
112
source = new HashMap <>();
112
113
source .put ("foo.bar.baz" , "baz1" );
113
114
source .put ("foo" , new HashMap <>(Collections .singletonMap ("bar" , "baz2" )));
114
- IngestDocument document2 = new IngestDocument ( source , Collections . emptyMap () );
115
+ IngestDocument document2 = TestIngestDocument . ofSourceAndMetadata ( source );
115
116
Processor processor2 = new DotExpanderProcessor ("_tag" , null , null , "foo.bar.baz" );
116
117
e = expectThrows (IllegalArgumentException .class , () -> processor2 .execute (document2 ));
117
118
assertThat (e .getMessage (), equalTo ("cannot expand [foo.bar.baz], because [foo.bar] is not an object field, but a value field" ));
@@ -120,7 +121,7 @@ public void testEscapeFields_valueField() throws Exception {
120
121
public void testEscapeFields_path () throws Exception {
121
122
Map <String , Object > source = new HashMap <>();
122
123
source .put ("foo" , new HashMap <>(Collections .singletonMap ("bar.baz" , "value" )));
123
- IngestDocument document = new IngestDocument ( source , Collections . emptyMap () );
124
+ IngestDocument document = TestIngestDocument . ofSourceAndMetadata ( source );
124
125
DotExpanderProcessor processor = new DotExpanderProcessor ("_tag" , null , "foo" , "bar.baz" );
125
126
processor .execute (document );
126
127
assertThat (document .getFieldValue ("foo" , Map .class ).size (), equalTo (1 ));
@@ -129,7 +130,7 @@ public void testEscapeFields_path() throws Exception {
129
130
130
131
source = new HashMap <>();
131
132
source .put ("field" , new HashMap <>(Collections .singletonMap ("foo.bar.baz" , "value" )));
132
- document = new IngestDocument ( source , Collections . emptyMap () );
133
+ document = TestIngestDocument . ofSourceAndMetadata ( source );
133
134
processor = new DotExpanderProcessor ("_tag" , null , "field" , "foo.bar.baz" );
134
135
processor .execute (document );
135
136
assertThat (document .getFieldValue ("field.foo" , Map .class ).size (), equalTo (1 ));
@@ -141,7 +142,7 @@ public void testEscapeFields_doNothingIfFieldNotInSourceDoc() throws Exception {
141
142
// asking to expand a (literal) field that is not present in the source document
142
143
Map <String , Object > source = new HashMap <>();
143
144
source .put ("foo.bar" , "baz1" );
144
- IngestDocument document = new IngestDocument ( source , Collections . emptyMap () );
145
+ IngestDocument document = TestIngestDocument . ofSourceAndMetadata ( source );
145
146
// abc.def does not exist in source, so don't mutate document
146
147
DotExpanderProcessor processor = new DotExpanderProcessor ("_tag" , null , null , "abc.def" );
147
148
processor .execute (document );
@@ -159,7 +160,7 @@ public void testEscapeFields_doNothingIfFieldNotInSourceDoc() throws Exception {
159
160
Map <String , Object > inner = new HashMap <>();
160
161
inner .put ("bar" , "baz1" );
161
162
source .put ("foo" , inner );
162
- document = new IngestDocument ( source , Collections . emptyMap () );
163
+ document = TestIngestDocument . ofSourceAndMetadata ( source );
163
164
// foo.bar, the literal value (as opposed to nested value) does not exist in source, so don't mutate document
164
165
processor = new DotExpanderProcessor ("_tag" , null , null , "foo.bar" );
165
166
processor .execute (document );
@@ -177,7 +178,7 @@ public void testOverride() throws Exception {
177
178
inner .put ("qux" , "quux" );
178
179
source .put ("foo" , inner );
179
180
source .put ("foo.bar" , "baz2" );
180
- IngestDocument document = new IngestDocument ( source , Map . of () );
181
+ IngestDocument document = TestIngestDocument . ofSourceAndMetadata ( source );
181
182
DotExpanderProcessor processor = new DotExpanderProcessor ("_tag" , null , null , "foo.bar" , true );
182
183
processor .execute (document );
183
184
assertThat (document .getFieldValue ("foo" , Map .class ).size (), equalTo (2 ));
@@ -189,7 +190,7 @@ public void testWildcard() throws Exception {
189
190
Map <String , Object > source = new HashMap <>();
190
191
source .put ("foo.bar" , "baz" );
191
192
source .put ("qux.quux" , "corge" );
192
- IngestDocument document = new IngestDocument ( source , Map . of () );
193
+ IngestDocument document = TestIngestDocument . ofSourceAndMetadata ( source );
193
194
DotExpanderProcessor processor = new DotExpanderProcessor ("_tag" , null , null , "*" );
194
195
processor .execute (document );
195
196
assertThat (document .getFieldValue ("foo" , Map .class ).size (), equalTo (1 ));
@@ -201,7 +202,7 @@ public void testWildcard() throws Exception {
201
202
Map <String , Object > inner = new HashMap <>();
202
203
inner .put ("bar.baz" , "qux" );
203
204
source .put ("foo" , inner );
204
- document = new IngestDocument ( source , Map . of () );
205
+ document = TestIngestDocument . ofSourceAndMetadata ( source );
205
206
processor = new DotExpanderProcessor ("_tag" , null , "foo" , "*" );
206
207
processor .execute (document );
207
208
assertThat (document .getFieldValue ("foo" , Map .class ).size (), equalTo (1 ));
@@ -212,7 +213,7 @@ public void testWildcard() throws Exception {
212
213
inner = new HashMap <>();
213
214
inner .put ("bar.baz" , "qux" );
214
215
source .put ("foo" , inner );
215
- document = new IngestDocument ( source , Map . of () );
216
+ document = TestIngestDocument . ofSourceAndMetadata ( source );
216
217
processor = new DotExpanderProcessor ("_tag" , null , null , "*" );
217
218
processor .execute (document );
218
219
assertThat (document .getFieldValue ("foo" , Map .class ).size (), equalTo (1 ));
0 commit comments