38
38
import java .util .Collections ;
39
39
import java .util .List ;
40
40
import java .util .Map ;
41
+ import java .util .Set ;
41
42
import java .util .SortedSet ;
42
43
import java .util .TreeSet ;
43
44
import java .util .function .Supplier ;
@@ -56,7 +57,7 @@ private static <T> SortedSet<T> set(T... values) {
56
57
return new TreeSet <>(Arrays .asList (values ));
57
58
}
58
59
59
- void assertFieldNames (SortedSet <String > expected , ParsedDocument doc ) {
60
+ void assertFieldNames (Set <String > expected , ParsedDocument doc ) {
60
61
String [] got = doc .rootDoc ().getValues ("_field_names" );
61
62
assertEquals (expected , set (got ));
62
63
}
@@ -120,6 +121,26 @@ public void testExplicitEnabled() throws Exception {
120
121
assertFieldNames (set ("field" , "field.keyword" , "_id" , "_version" , "_seq_no" , "_primary_term" , "_source" ), doc );
121
122
}
122
123
124
+ public void testDedup () throws Exception {
125
+ String mapping = XContentFactory .jsonBuilder ().startObject ().startObject ("type" )
126
+ .startObject ("_field_names" ).field ("enabled" , true ).endObject ()
127
+ .endObject ().endObject ().string ();
128
+ DocumentMapper docMapper = createIndex ("test" ).mapperService ().documentMapperParser ().parse ("type" , new CompressedXContent (mapping ));
129
+ FieldNamesFieldMapper fieldNamesMapper = docMapper .metadataMapper (FieldNamesFieldMapper .class );
130
+ assertTrue (fieldNamesMapper .fieldType ().isEnabled ());
131
+
132
+ ParsedDocument doc = docMapper .parse (SourceToParse .source ("test" , "type" , "1" , XContentFactory .jsonBuilder ()
133
+ .startObject ()
134
+ .field ("field" , 3 ) // will create 2 lucene fields under the hood: index and doc values
135
+ .endObject ()
136
+ .bytes (),
137
+ XContentType .JSON ));
138
+
139
+ Set <String > fields = set ("field" , "_id" , "_version" , "_seq_no" , "_primary_term" , "_source" );
140
+ assertFieldNames (fields , doc );
141
+ assertEquals (fields .size (), doc .rootDoc ().getValues ("_field_names" ).length );
142
+ }
143
+
123
144
public void testDisabled () throws Exception {
124
145
String mapping = XContentFactory .jsonBuilder ().startObject ().startObject ("type" )
125
146
.startObject ("_field_names" ).field ("enabled" , false ).endObject ()
0 commit comments