@@ -30,6 +30,10 @@ private static void collectTypes(Map<String, ?> mapping, Set<String> types) {
3030 });
3131 }
3232
33+ private static void collectFieldsAndSubFields (Map <String , ?> mapping , Set <String > fields , Set <String > subFields ) {
34+ MappingVisitor .visitMapping (mapping , (f , m ) -> fields .add (f ), (f , m ) -> subFields .add (f ));
35+ }
36+
3337 public void testCountTopLevelFields () {
3438 Map <String , Object > mapping = new HashMap <>();
3539 Set <String > fields = new HashSet <>();
@@ -45,14 +49,14 @@ public void testCountTopLevelFields() {
4549 collectTypes (mapping , fields );
4650 assertEquals (Collections .singleton ("keyword" ), fields );
4751
48- Map <String , Object > IndexField = new HashMap <>();
49- IndexField .put ("type" , "integer" );
50- properties .put ("bar" , IndexField );
52+ Map <String , Object > indexField = new HashMap <>();
53+ indexField .put ("type" , "integer" );
54+ properties .put ("bar" , indexField );
5155 fields = new HashSet <>();
5256 collectTypes (mapping , fields );
5357 assertEquals (new HashSet <>(Arrays .asList ("keyword" , "integer" )), fields );
5458
55- properties .put ("baz" , IndexField );
59+ properties .put ("baz" , indexField );
5660 fields = new HashSet <>();
5761 collectTypes (mapping , fields );
5862 assertEquals (new HashSet <>(Arrays .asList ("keyword" , "integer" )), fields );
@@ -80,6 +84,35 @@ public void testCountMultiFields() {
8084 assertEquals (new HashSet <>(Arrays .asList ("keyword" , "text" )), usedFields );
8185 }
8286
87+ public void testFieldsAndMultiFields () {
88+ Map <String , Object > keywordType = new HashMap <>();
89+ keywordType .put ("type" , "keyword" );
90+
91+ Map <String , Object > textType = new HashMap <>();
92+ textType .put ("type" , "text" );
93+
94+ Map <String , Object > multiFields = new HashMap <>();
95+ multiFields .put ("keyword" , keywordType );
96+ textType .put ("fields" , multiFields );
97+
98+ Map <String , Object > subObject = new HashMap <>();
99+ subObject .put ("properties" , Map .of ("baz" , keywordType ));
100+ subObject .put ("type" , "keyword" );
101+
102+ Map <String , Object > properties = new HashMap <>();
103+ properties .put ("foo" , textType );
104+ properties .put ("bar" , subObject );
105+
106+ Map <String , Object > mapping = new HashMap <>();
107+ mapping .put ("properties" , properties );
108+
109+ Set <String > fields = new HashSet <>();
110+ Set <String > subFields = new HashSet <>();
111+ collectFieldsAndSubFields (mapping , fields , subFields );
112+ assertEquals (Set .of ("foo" , "bar" , "bar.baz" ), fields );
113+ assertEquals (Set .of ("foo.keyword" ), subFields );
114+ }
115+
83116 public void testCountInnerFields () {
84117 Map <String , Object > keywordField = new HashMap <>();
85118 keywordField .put ("type" , "keyword" );
0 commit comments