@@ -205,6 +205,98 @@ private static XContentBuilder createNestedTestMapping() {
205
205
}
206
206
}
207
207
208
+ private static XContentBuilder createNestedTestMappingForArray () {
209
+ try {
210
+ return jsonBuilder ().startObject ()
211
+ .startObject ("composite" )
212
+ .startObject ("startree-1" )
213
+ .field ("type" , "star_tree" )
214
+ .startObject ("config" )
215
+ .startObject ("date_dimension" )
216
+ .field ("name" , "timestamp" )
217
+ .endObject ()
218
+ .startArray ("ordered_dimensions" )
219
+ .startObject ()
220
+ .field ("name" , "status" )
221
+ .endObject ()
222
+ .startObject ()
223
+ .field ("name" , "nested.nested1.keyword_dv" )
224
+ .endObject ()
225
+ .endArray ()
226
+ .startArray ("metrics" )
227
+ .startObject ()
228
+ .field ("name" , "nested3.numeric_dv" )
229
+ .endObject ()
230
+ .endArray ()
231
+ .endObject ()
232
+ .endObject ()
233
+ .endObject ()
234
+ .startObject ("properties" )
235
+ .startObject ("timestamp" )
236
+ .field ("type" , "date" )
237
+ .endObject ()
238
+ .startObject ("status" )
239
+ .field ("type" , "integer" )
240
+ .endObject ()
241
+ .startObject ("nested3" )
242
+ .startObject ("properties" )
243
+ .startObject ("numeric_dv" )
244
+ .field ("type" , "integer" )
245
+ .field ("doc_values" , true )
246
+ .endObject ()
247
+ .endObject ()
248
+ .endObject ()
249
+ .startObject ("numeric" )
250
+ .field ("type" , "integer" )
251
+ .field ("doc_values" , false )
252
+ .endObject ()
253
+ .startObject ("nested" )
254
+ .startObject ("properties" )
255
+ .startObject ("nested1" )
256
+ .startObject ("properties" )
257
+ .startObject ("status" )
258
+ .field ("type" , "integer" )
259
+ .field ("doc_values" , true )
260
+ .endObject ()
261
+ .startObject ("keyword_dv" )
262
+ .field ("type" , "keyword" )
263
+ .field ("doc_values" , true )
264
+ .endObject ()
265
+ .endObject ()
266
+ .endObject ()
267
+ .endObject ()
268
+ .endObject ()
269
+ .startObject ("nested-not-startree" )
270
+ .startObject ("properties" )
271
+ .startObject ("nested1" )
272
+ .startObject ("properties" )
273
+ .startObject ("status" )
274
+ .field ("type" , "integer" )
275
+ .field ("doc_values" , true )
276
+ .endObject ()
277
+ .startObject ("keyword_dv" )
278
+ .field ("type" , "keyword" )
279
+ .field ("doc_values" , true )
280
+ .endObject ()
281
+ .endObject ()
282
+ .endObject ()
283
+ .endObject ()
284
+ .endObject ()
285
+ .startObject ("keyword" )
286
+ .field ("type" , "keyword" )
287
+ .field ("doc_values" , false )
288
+ .endObject ()
289
+ .startObject ("ip" )
290
+ .field ("type" , "ip" )
291
+ .field ("doc_values" , false )
292
+ .endObject ()
293
+ .endObject ()
294
+ .endObject ();
295
+ } catch (IOException e ) {
296
+ throw new IllegalStateException (e );
297
+ }
298
+ }
299
+
208
300
private static XContentBuilder createDateTestMapping (boolean duplicate ) {
209
301
try {
210
302
return jsonBuilder ().startObject ()
@@ -693,6 +785,7 @@ public void testCompositeIndexWithArraysInCompositeField() throws IOException {
693
785
}
694
786
695
787
public void testCompositeIndexWithArraysInNestedCompositeField () throws IOException {
788
+ // here nested.nested1.status is part of the composite field but "nested" field itself is an array
696
789
prepareCreate (TEST_INDEX ).setSettings (settings ).setMapping (createNestedTestMapping ()).get ();
697
790
// Attempt to index a document with an array field
698
791
XContentBuilder doc = jsonBuilder ().startObject ()
@@ -726,7 +819,7 @@ public void testCompositeIndexWithArraysInNestedCompositeField() throws IOExcept
726
819
727
820
public void testCompositeIndexWithArraysInChildNestedCompositeField () throws IOException {
728
821
prepareCreate (TEST_INDEX ).setSettings (settings ).setMapping (createNestedTestMapping ()).get ();
729
- // Attempt to index a document with an array field
822
+ // here nested.nested1.status is part of the composite field but "nested.nested1" field is an array
730
823
XContentBuilder doc = jsonBuilder ().startObject ()
731
824
.field ("timestamp" , "2023-06-01T12:00:00Z" )
732
825
.startObject ("nested" )
@@ -754,6 +847,43 @@ public void testCompositeIndexWithArraysInChildNestedCompositeField() throws IOE
754
847
);
755
848
}
756
849
850
+ public void testCompositeIndexWithArraysInNestedCompositeFieldSameNameAsNormalField () throws IOException {
851
+ prepareCreate (TEST_INDEX ).setSettings (settings ).setMapping (createNestedTestMappingForArray ()).get ();
852
+ // here status is part of the composite field but "nested.nested1.status" field is an array which is not
853
+ // part of composite field
854
+ XContentBuilder doc = jsonBuilder ().startObject ()
855
+ .field ("timestamp" , "2023-06-01T12:00:00Z" )
856
+ .startObject ("nested" )
857
+ .startObject ("nested1" )
858
+ .startArray ("status" )
859
+ .value (10 )
860
+ .value (20 )
861
+ .value (30 )
862
+ .endArray ()
863
+ .endObject ()
864
+ .endObject ()
865
+ .field ("status" , "200" )
866
+ .endObject ();
867
+ // Index the document and refresh
868
+ // Index the document and refresh
869
+ IndexResponse indexResponse = client ().prepareIndex (TEST_INDEX ).setSource (doc ).get ();
870
+
871
+ assertEquals (RestStatus .CREATED , indexResponse .status ());
872
+
873
+ client ().admin ().indices ().prepareRefresh (TEST_INDEX ).get ();
874
+ // Verify the document was indexed
875
+ SearchResponse searchResponse = client ().prepareSearch (TEST_INDEX ).setQuery (QueryBuilders .matchAllQuery ()).get ();
876
+
877
+ assertEquals (1 , searchResponse .getHits ().getTotalHits ().value );
878
+
879
+ // Verify the values in the indexed document
880
+ SearchHit hit = searchResponse .getHits ().getAt (0 );
881
+ assertEquals ("2023-06-01T12:00:00Z" , hit .getSourceAsMap ().get ("timestamp" ));
882
+
883
+ int values = Integer .parseInt ((String ) hit .getSourceAsMap ().get ("status" ));
884
+ assertEquals (200 , values );
885
+ }
886
+
757
887
public void testCompositeIndexWithNestedArraysInNonCompositeField () throws IOException {
758
888
prepareCreate (TEST_INDEX ).setSettings (settings ).setMapping (createNestedTestMapping ()).get ();
759
889
// Attempt to index a document with an array field
0 commit comments