42
42
import org .elasticsearch .common .unit .Fuzziness ;
43
43
import org .elasticsearch .core .Nullable ;
44
44
import org .elasticsearch .features .NodeFeature ;
45
+ import org .elasticsearch .index .IndexMode ;
45
46
import org .elasticsearch .index .IndexVersion ;
46
47
import org .elasticsearch .index .IndexVersions ;
47
48
import org .elasticsearch .index .analysis .IndexAnalyzers ;
90
91
import static org .elasticsearch .core .Strings .format ;
91
92
import static org .elasticsearch .index .IndexSettings .IGNORE_ABOVE_SETTING ;
92
93
import static org .elasticsearch .index .mapper .FieldArrayContext .getOffsetsFieldName ;
94
+ import static org .elasticsearch .index .mapper .Mapper .IgnoreAbove .getIgnoreAboveDefaultValue ;
93
95
94
96
/**
95
97
* A field mapper for keywords. This mapper accepts strings and indexes them as-is.
@@ -169,6 +171,7 @@ public static final class Builder extends FieldMapper.DimensionBuilder {
169
171
);
170
172
private final Parameter <Integer > ignoreAbove ;
171
173
private final int ignoreAboveDefault ;
174
+ private final IndexMode indexMode ;
172
175
173
176
private final Parameter <String > indexOptions = TextParams .keywordIndexOptions (m -> toType (m ).indexOptions );
174
177
private final Parameter <Boolean > hasNorms = TextParams .norms (false , m -> toType (m ).fieldType .omitNorms () == false );
@@ -206,16 +209,36 @@ public Builder(final String name, final MappingParserContext mappingParserContex
206
209
mappingParserContext .scriptCompiler (),
207
210
IGNORE_ABOVE_SETTING .get (mappingParserContext .getSettings ()),
208
211
mappingParserContext .getIndexSettings ().getIndexVersionCreated (),
212
+ mappingParserContext .getIndexSettings ().getMode (),
209
213
mappingParserContext .getIndexSettings ().sourceKeepMode ()
210
214
);
211
215
}
212
216
213
217
Builder (
218
+ String name ,
219
+ IndexAnalyzers indexAnalyzers ,
220
+ ScriptCompiler scriptCompiler ,
221
+ IndexVersion indexCreatedVersion ,
222
+ SourceKeepMode sourceKeepMode
223
+ ) {
224
+ this (
225
+ name ,
226
+ indexAnalyzers ,
227
+ scriptCompiler ,
228
+ getIgnoreAboveDefaultValue (IndexMode .STANDARD , indexCreatedVersion ),
229
+ indexCreatedVersion ,
230
+ IndexMode .STANDARD ,
231
+ sourceKeepMode
232
+ );
233
+ }
234
+
235
+ private Builder (
214
236
String name ,
215
237
IndexAnalyzers indexAnalyzers ,
216
238
ScriptCompiler scriptCompiler ,
217
239
int ignoreAboveDefault ,
218
240
IndexVersion indexCreatedVersion ,
241
+ IndexMode indexMode ,
219
242
SourceKeepMode indexSourceKeepMode
220
243
) {
221
244
super (name );
@@ -245,17 +268,13 @@ public Builder(final String name, final MappingParserContext mappingParserContex
245
268
}
246
269
}).precludesParameters (normalizer );
247
270
this .ignoreAboveDefault = ignoreAboveDefault ;
248
- this .ignoreAbove = Parameter .intParam ("ignore_above" , true , m -> toType (m ).fieldType ().ignoreAbove (), ignoreAboveDefault )
249
- .addValidator (v -> {
250
- if (v < 0 ) {
251
- throw new IllegalArgumentException ("[ignore_above] must be positive, got [" + v + "]" );
252
- }
253
- });
271
+ this .ignoreAbove = Parameter .ignoreAboveParam (m -> toType (m ).fieldType ().ignoreAbove ().get (), ignoreAboveDefault );
272
+ this .indexMode = indexMode ;
254
273
this .indexSourceKeepMode = indexSourceKeepMode ;
255
274
}
256
275
257
276
public Builder (String name , IndexVersion indexCreatedVersion ) {
258
- this (name , null , ScriptCompiler .NONE , Integer . MAX_VALUE , indexCreatedVersion , SourceKeepMode .NONE );
277
+ this (name , null , ScriptCompiler .NONE , indexCreatedVersion , SourceKeepMode .NONE );
259
278
}
260
279
261
280
public Builder ignoreAbove (int ignoreAbove ) {
@@ -418,7 +437,9 @@ public KeywordFieldMapper build(MapperBuilderContext context) {
418
437
419
438
public static final class KeywordFieldType extends StringFieldType {
420
439
421
- private final int ignoreAbove ;
440
+ private static final IgnoreAbove IGNORE_ABOVE_DEFAULT = new IgnoreAbove (null , IndexMode .STANDARD );
441
+
442
+ private final IgnoreAbove ignoreAbove ;
422
443
private final String nullValue ;
423
444
private final NamedAnalyzer normalizer ;
424
445
private final boolean eagerGlobalOrdinals ;
@@ -446,18 +467,22 @@ public KeywordFieldType(
446
467
);
447
468
this .eagerGlobalOrdinals = builder .eagerGlobalOrdinals .getValue ();
448
469
this .normalizer = normalizer ;
449
- this .ignoreAbove = builder .ignoreAbove .getValue ();
470
+ this .ignoreAbove = new IgnoreAbove ( builder .ignoreAbove .getValue (), builder . indexMode , builder . indexCreatedVersion );
450
471
this .nullValue = builder .nullValue .getValue ();
451
472
this .scriptValues = builder .scriptValues ();
452
473
this .isDimension = builder .dimension .getValue ();
453
474
this .isSyntheticSource = isSyntheticSource ;
454
475
this .originalName = isSyntheticSource ? name + "._original" : null ;
455
476
}
456
477
478
+ public KeywordFieldType (String name ) {
479
+ this (name , true , true , Collections .emptyMap ());
480
+ }
481
+
457
482
public KeywordFieldType (String name , boolean isIndexed , boolean hasDocValues , Map <String , String > meta ) {
458
483
super (name , isIndexed , false , hasDocValues , TextSearchInfo .SIMPLE_MATCH_ONLY , meta );
459
484
this .normalizer = Lucene .KEYWORD_ANALYZER ;
460
- this .ignoreAbove = Integer . MAX_VALUE ;
485
+ this .ignoreAbove = IGNORE_ABOVE_DEFAULT ;
461
486
this .nullValue = null ;
462
487
this .eagerGlobalOrdinals = false ;
463
488
this .scriptValues = null ;
@@ -466,10 +491,6 @@ public KeywordFieldType(String name, boolean isIndexed, boolean hasDocValues, Ma
466
491
this .originalName = null ;
467
492
}
468
493
469
- public KeywordFieldType (String name ) {
470
- this (name , true , true , Collections .emptyMap ());
471
- }
472
-
473
494
public KeywordFieldType (String name , FieldType fieldType ) {
474
495
super (
475
496
name ,
@@ -480,7 +501,7 @@ public KeywordFieldType(String name, FieldType fieldType) {
480
501
Collections .emptyMap ()
481
502
);
482
503
this .normalizer = Lucene .KEYWORD_ANALYZER ;
483
- this .ignoreAbove = Integer . MAX_VALUE ;
504
+ this .ignoreAbove = IGNORE_ABOVE_DEFAULT ;
484
505
this .nullValue = null ;
485
506
this .eagerGlobalOrdinals = false ;
486
507
this .scriptValues = null ;
@@ -492,7 +513,7 @@ public KeywordFieldType(String name, FieldType fieldType) {
492
513
public KeywordFieldType (String name , NamedAnalyzer analyzer ) {
493
514
super (name , true , false , true , textSearchInfo (Defaults .FIELD_TYPE , null , analyzer , analyzer ), Collections .emptyMap ());
494
515
this .normalizer = Lucene .KEYWORD_ANALYZER ;
495
- this .ignoreAbove = Integer . MAX_VALUE ;
516
+ this .ignoreAbove = IGNORE_ABOVE_DEFAULT ;
496
517
this .nullValue = null ;
497
518
this .eagerGlobalOrdinals = false ;
498
519
this .scriptValues = null ;
@@ -800,10 +821,7 @@ protected String parseSourceValue(Object value) {
800
821
}
801
822
802
823
private String applyIgnoreAboveAndNormalizer (String value ) {
803
- if (value .length () > ignoreAbove ) {
804
- return null ;
805
- }
806
-
824
+ if (ignoreAbove .isIgnored (value )) return null ;
807
825
return normalizeValue (normalizer (), name (), value );
808
826
}
809
827
@@ -922,7 +940,7 @@ public CollapseType collapseType() {
922
940
923
941
/** Values that have more chars than the return value of this method will
924
942
* be skipped at parsing time. */
925
- public int ignoreAbove () {
943
+ public IgnoreAbove ignoreAbove () {
926
944
return ignoreAbove ;
927
945
}
928
946
@@ -974,7 +992,7 @@ public String originalName() {
974
992
975
993
private final IndexAnalyzers indexAnalyzers ;
976
994
private final int ignoreAboveDefault ;
977
- private final int ignoreAbove ;
995
+ private final IndexMode indexMode ;
978
996
private final String offsetsFieldName ;
979
997
private final SourceKeepMode indexSourceKeepMode ;
980
998
private final String originalName ;
@@ -1003,7 +1021,7 @@ private KeywordFieldMapper(
1003
1021
this .indexCreatedVersion = builder .indexCreatedVersion ;
1004
1022
this .isSyntheticSource = isSyntheticSource ;
1005
1023
this .ignoreAboveDefault = builder .ignoreAboveDefault ;
1006
- this .ignoreAbove = builder .ignoreAbove . getValue () ;
1024
+ this .indexMode = builder .indexMode ;
1007
1025
this .offsetsFieldName = offsetsFieldName ;
1008
1026
this .indexSourceKeepMode = indexSourceKeepMode ;
1009
1027
this .originalName = mappedFieldType .originalName ();
@@ -1060,7 +1078,7 @@ private boolean indexValue(DocumentParserContext context, XContentString value)
1060
1078
return false ;
1061
1079
}
1062
1080
1063
- if (value . stringLength () > fieldType ().ignoreAbove ()) {
1081
+ if (fieldType ().ignoreAbove (). isIgnored ( value )) {
1064
1082
context .addIgnoredField (fullPath ());
1065
1083
if (isSyntheticSource ) {
1066
1084
// Save a copy of the field so synthetic source can load it
@@ -1151,9 +1169,15 @@ public Map<String, NamedAnalyzer> indexAnalyzers() {
1151
1169
1152
1170
@ Override
1153
1171
public FieldMapper .Builder getMergeBuilder () {
1154
- return new Builder (leafName (), indexAnalyzers , scriptCompiler , ignoreAboveDefault , indexCreatedVersion , indexSourceKeepMode )
1155
- .dimension (fieldType ().isDimension ())
1156
- .init (this );
1172
+ return new Builder (
1173
+ leafName (),
1174
+ indexAnalyzers ,
1175
+ scriptCompiler ,
1176
+ ignoreAboveDefault ,
1177
+ indexCreatedVersion ,
1178
+ indexMode ,
1179
+ indexSourceKeepMode
1180
+ ).dimension (fieldType ().isDimension ()).init (this );
1157
1181
}
1158
1182
1159
1183
@ Override
@@ -1216,7 +1240,7 @@ protected BytesRef preserve(BytesRef value) {
1216
1240
}
1217
1241
}
1218
1242
1219
- if (fieldType ().ignoreAbove != Integer . MAX_VALUE ) {
1243
+ if (fieldType ().ignoreAbove . isSet () ) {
1220
1244
layers .add (new CompositeSyntheticFieldLoader .StoredFieldLayer (originalName ) {
1221
1245
@ Override
1222
1246
protected void writeValue (Object value , XContentBuilder b ) throws IOException {
0 commit comments