@@ -133,6 +133,7 @@ public void startUp() throws Exception {
133
133
createIndexDocs ();
134
134
createIndexWithFullType ();
135
135
createIndexForResourceNull ("st_index4" );
136
+ createIndexWithNestType ();
136
137
}
137
138
138
139
/** create a index,and bulk some documents */
@@ -156,6 +157,31 @@ private void createIndexDocsByName(String indexName, List<String> testDataSet) {
156
157
esRestClient .bulk (requestBody .toString ());
157
158
}
158
159
160
+ private void createIndexWithNestType () throws IOException , InterruptedException {
161
+ String mapping =
162
+ IOUtils .toString (
163
+ ContainerUtil .getResourcesFile ("/elasticsearch/st_index_nest_mapping.json" )
164
+ .toURI (),
165
+ StandardCharsets .UTF_8 );
166
+ esRestClient .createIndex ("st_index_nest" , mapping );
167
+ esRestClient .createIndex ("st_index_nest_copy" , mapping );
168
+ BulkResponse response =
169
+ esRestClient .bulk (
170
+ "{ \" index\" : { \" _index\" : \" st_index_nest\" , \" _id\" : \" 1\" } }\n "
171
+ + IOUtils .toString (
172
+ ContainerUtil .getResourcesFile (
173
+ "/elasticsearch/st_index_nest_data.json" )
174
+ .toURI (),
175
+ StandardCharsets .UTF_8 )
176
+ .replace ("\n " , "" )
177
+ + "\n " );
178
+ Assertions .assertFalse (response .isErrors (), response .getResponse ());
179
+ // waiting index refresh
180
+ Thread .sleep (INDEX_REFRESH_MILL_DELAY );
181
+ Assertions .assertEquals (
182
+ 3 , esRestClient .getIndexDocsCount ("st_index_nest" ).get (0 ).getDocsCount ());
183
+ }
184
+
159
185
private void createIndexWithFullType () throws IOException , InterruptedException {
160
186
String mapping =
161
187
IOUtils .toString (
@@ -202,6 +228,21 @@ public void testElasticsearchWithSchema(TestContainer container)
202
228
Assertions .assertIterableEquals (mapTestDatasetForDSL (), sinkData );
203
229
}
204
230
231
+ @ TestTemplate
232
+ public void testElasticsearchWithNestSchema (TestContainer container )
233
+ throws IOException , InterruptedException {
234
+ Container .ExecResult execResult =
235
+ container .executeJob ("/elasticsearch/elasticsearch_source_and_sink_with_nest.conf" );
236
+ Assertions .assertEquals (0 , execResult .getExitCode ());
237
+
238
+ List <String > sinkData = readSinkDataWithNestSchema ("st_index_nest_copy" );
239
+ String data =
240
+ "{\" address\" :[{\" zipcode\" :\" 10001\" ,\" city\" :\" New York\" ,\" street\" :\" 123 Main St\" },"
241
+ + "{\" zipcode\" :\" 90001\" ,\" city\" :\" Los Angeles\" ,\" street\" :\" 456 Elm St\" }],\" name\" :\" John Doe\" }" ;
242
+
243
+ Assertions .assertIterableEquals (Lists .newArrayList (data ), sinkData );
244
+ }
245
+
205
246
@ TestTemplate
206
247
public void testElasticsSearchWithMultiSourceByFilter (TestContainer container )
207
248
throws InterruptedException , IOException {
@@ -546,6 +587,13 @@ private List<String> readSinkDataWithSchema(String index) throws InterruptedExce
546
587
return getDocsWithTransformTimestamp (source , index );
547
588
}
548
589
590
+ private List <String > readSinkDataWithNestSchema (String index ) throws InterruptedException {
591
+ // wait for index refresh
592
+ Thread .sleep (INDEX_REFRESH_MILL_DELAY );
593
+ List <String > source = Lists .newArrayList ("name" , "address" );
594
+ return getDocsWithNestType (source , index );
595
+ }
596
+
549
597
private List <String > readMultiSinkData (String index , List <String > source )
550
598
throws InterruptedException {
551
599
// wait for index refresh
@@ -604,6 +652,25 @@ private List<String> getDocsWithTransformTimestamp(List<String> source, String i
604
652
return docs ;
605
653
}
606
654
655
+ private List <String > getDocsWithNestType (List <String > source , String index ) {
656
+ Map <String , Object > query = new HashMap <>();
657
+ query .put ("match_all" , new HashMap <>());
658
+ ScrollResult scrollResult = esRestClient .searchByScroll (index , source , query , "1m" , 1000 );
659
+ scrollResult
660
+ .getDocs ()
661
+ .forEach (
662
+ x -> {
663
+ x .remove ("_index" );
664
+ x .remove ("_type" );
665
+ x .remove ("_id" );
666
+ });
667
+ List <String > docs =
668
+ scrollResult .getDocs ().stream ()
669
+ .map (JsonUtils ::toJsonString )
670
+ .collect (Collectors .toList ());
671
+ return docs ;
672
+ }
673
+
607
674
private List <String > getDocsWithTransformDate (List <String > source , String index ) {
608
675
return getDocsWithTransformDate (source , index , Collections .emptyList ());
609
676
}
@@ -739,6 +806,13 @@ private List<String> mapTestDatasetForDSL(List<String> testDataset) {
739
806
.collect (Collectors .toList ());
740
807
}
741
808
809
+ private List <String > mapTestDatasetForNest (List <String > testDataset ) {
810
+ return testDataset .stream ()
811
+ .map (JsonUtils ::parseObject )
812
+ .map (JsonNode ::toString )
813
+ .collect (Collectors .toList ());
814
+ }
815
+
742
816
/**
743
817
* Use custom filtering criteria to query data
744
818
*
0 commit comments