@@ -87,14 +87,52 @@ protected void minimalMappingWithExplicitIndexOptions(XContentBuilder b) throws
8787 b .field ("prune" , true );
8888 b .startObject ("pruning_config" );
8989 {
90- b .field ("tokens_freq_ratio_threshold" , TokenPruningConfig .DEFAULT_TOKENS_FREQ_RATIO_THRESHOLD );
90+ b .field ("tokens_freq_ratio_threshold" , 3.0f );
91+ b .field ("tokens_weight_threshold" , 0.5f );
92+ }
93+ b .endObject ();
94+ }
95+ b .endObject ();
96+ }
97+
98+ protected void serializedMappingWithSomeIndexOptions (XContentBuilder b ) throws IOException {
99+ b .field ("type" , "sparse_vector" );
100+ b .startObject ("index_options" );
101+ {
102+ b .field ("prune" , true );
103+ b .startObject ("pruning_config" );
104+ {
105+ b .field ("tokens_freq_ratio_threshold" , 3.0f );
91106 b .field ("tokens_weight_threshold" , TokenPruningConfig .DEFAULT_TOKENS_WEIGHT_THRESHOLD );
92107 }
93108 b .endObject ();
94109 }
95110 b .endObject ();
96111 }
97112
113+ protected void minimalMappingWithSomeExplicitIndexOptions (XContentBuilder b ) throws IOException {
114+ b .field ("type" , "sparse_vector" );
115+ b .startObject ("index_options" );
116+ {
117+ b .field ("prune" , true );
118+ b .startObject ("pruning_config" );
119+ {
120+ b .field ("tokens_freq_ratio_threshold" , 3.0f );
121+ }
122+ b .endObject ();
123+ }
124+ b .endObject ();
125+ }
126+
127+ protected void mappingWithIndexOptionsOnlyPruneTrue (XContentBuilder b ) throws IOException {
128+ b .field ("type" , "sparse_vector" );
129+ b .startObject ("index_options" );
130+ {
131+ b .field ("prune" , true );
132+ }
133+ b .endObject ();
134+ }
135+
98136 protected void mappingWithIndexOptionsPruneFalse (XContentBuilder b ) throws IOException {
99137 b .field ("type" , "sparse_vector" );
100138 b .startObject ("index_options" );
@@ -133,7 +171,7 @@ private static int getFrequency(TokenStream tk) throws IOException {
133171
134172 public void testDefaults () throws Exception {
135173 DocumentMapper mapper = createDocumentMapper (fieldMapping (this ::minimalMapping ));
136- assertEquals (Strings .toString (fieldMapping (this ::minimalMappingWithExplicitIndexOptions )), mapper .mappingSource ().toString ());
174+ assertEquals (Strings .toString (fieldMapping (this ::minimalMapping )), mapper .mappingSource ().toString ());
137175
138176 ParsedDocument doc1 = mapper .parse (source (this ::writeField ));
139177
@@ -159,7 +197,7 @@ public void testDefaults() throws Exception {
159197
160198 public void testMappingWithoutIndexOptionsUsesDefaults () throws Exception {
161199 DocumentMapper mapper = createDocumentMapper (fieldMapping (this ::minimalMapping ));
162- assertEquals (Strings .toString (fieldMapping (this ::minimalMappingWithExplicitIndexOptions )), mapper .mappingSource ().toString ());
200+ assertEquals (Strings .toString (fieldMapping (this ::minimalMapping )), mapper .mappingSource ().toString ());
163201
164202 IndexVersion preIndexOptionsVersion = IndexVersionUtils .randomVersionBetween (
165203 random (),
@@ -170,6 +208,20 @@ public void testMappingWithoutIndexOptionsUsesDefaults() throws Exception {
170208 assertEquals (Strings .toString (fieldMapping (this ::minimalMapping )), previousMapper .mappingSource ().toString ());
171209 }
172210
211+ public void testMappingWithExplicitIndexOptions () throws Exception {
212+ DocumentMapper mapper = createDocumentMapper (fieldMapping (this ::minimalMappingWithExplicitIndexOptions ));
213+ assertEquals (Strings .toString (fieldMapping (this ::minimalMappingWithExplicitIndexOptions )), mapper .mappingSource ().toString ());
214+
215+ mapper = createDocumentMapper (fieldMapping (this ::mappingWithIndexOptionsPruneFalse ));
216+ assertEquals (Strings .toString (fieldMapping (this ::mappingWithIndexOptionsPruneFalse )), mapper .mappingSource ().toString ());
217+
218+ mapper = createDocumentMapper (fieldMapping (this ::minimalMappingWithSomeExplicitIndexOptions ));
219+ assertEquals (Strings .toString (fieldMapping (this ::serializedMappingWithSomeIndexOptions )), mapper .mappingSource ().toString ());
220+
221+ mapper = createDocumentMapper (fieldMapping (this ::mappingWithIndexOptionsOnlyPruneTrue ));
222+ assertEquals (Strings .toString (fieldMapping (this ::mappingWithIndexOptionsOnlyPruneTrue )), mapper .mappingSource ().toString ());
223+ }
224+
173225 public void testDotInFieldName () throws Exception {
174226 DocumentMapper mapper = createDocumentMapper (fieldMapping (this ::minimalMapping ));
175227 ParsedDocument parsedDocument = mapper .parse (source (b -> b .field ("field" , Map .of ("foo.bar" , 10 , "foobar" , 20 ))));
0 commit comments