92
92
import static org .elasticsearch .index .IndexSettings .IGNORE_ABOVE_SETTING ;
93
93
import static org .elasticsearch .index .IndexSettings .USE_DOC_VALUES_SKIPPER ;
94
94
import static org .elasticsearch .index .mapper .FieldArrayContext .getOffsetsFieldName ;
95
+ import static org .elasticsearch .index .mapper .Mapper .IgnoreAbove .getIgnoreAboveDefaultValue ;
95
96
96
97
/**
97
98
* A field mapper for keywords. This mapper accepts strings and indexes them as-is.
@@ -232,15 +233,14 @@ public Builder(final String name, final MappingParserContext mappingParserContex
232
233
String name ,
233
234
IndexAnalyzers indexAnalyzers ,
234
235
ScriptCompiler scriptCompiler ,
235
- int ignoreAboveDefault ,
236
236
IndexVersion indexCreatedVersion ,
237
237
SourceKeepMode sourceKeepMode
238
238
) {
239
239
this (
240
240
name ,
241
241
indexAnalyzers ,
242
242
scriptCompiler ,
243
- ignoreAboveDefault ,
243
+ getIgnoreAboveDefaultValue ( IndexMode . STANDARD , indexCreatedVersion ) ,
244
244
indexCreatedVersion ,
245
245
IndexMode .STANDARD ,
246
246
null ,
@@ -289,12 +289,7 @@ private Builder(
289
289
}
290
290
}).precludesParameters (normalizer );
291
291
this .ignoreAboveDefault = ignoreAboveDefault ;
292
- this .ignoreAbove = Parameter .intParam ("ignore_above" , true , m -> toType (m ).fieldType ().ignoreAbove (), ignoreAboveDefault )
293
- .addValidator (v -> {
294
- if (v < 0 ) {
295
- throw new IllegalArgumentException ("[ignore_above] must be positive, got [" + v + "]" );
296
- }
297
- });
292
+ this .ignoreAbove = Parameter .ignoreAboveParam (m -> toType (m ).fieldType ().ignoreAbove ().get (), ignoreAboveDefault );
298
293
this .indexSortConfig = indexSortConfig ;
299
294
this .indexMode = indexMode ;
300
295
this .enableDocValuesSkipper = enableDocValuesSkipper ;
@@ -303,7 +298,7 @@ private Builder(
303
298
}
304
299
305
300
public Builder (String name , IndexVersion indexCreatedVersion ) {
306
- this (name , null , ScriptCompiler .NONE , Integer . MAX_VALUE , indexCreatedVersion , SourceKeepMode .NONE );
301
+ this (name , null , ScriptCompiler .NONE , indexCreatedVersion , SourceKeepMode .NONE );
307
302
}
308
303
309
304
public static Builder buildWithDocValuesSkipper (
@@ -316,7 +311,7 @@ public static Builder buildWithDocValuesSkipper(
316
311
name ,
317
312
null ,
318
313
ScriptCompiler .NONE ,
319
- Integer . MAX_VALUE ,
314
+ getIgnoreAboveDefaultValue ( indexMode , indexCreatedVersion ) ,
320
315
indexCreatedVersion ,
321
316
indexMode ,
322
317
// Sort config is used to decide if DocValueSkippers can be used. Since skippers are forced, a sort config is not needed.
@@ -537,14 +532,15 @@ private static boolean indexSortConfigByHostName(final IndexSortConfig indexSort
537
532
538
533
public static final class KeywordFieldType extends StringFieldType {
539
534
540
- private final int ignoreAbove ;
535
+ private static final IgnoreAbove IGNORE_ABOVE_DEFAULT = new IgnoreAbove (null , IndexMode .STANDARD );
536
+
537
+ private final IgnoreAbove ignoreAbove ;
541
538
private final String nullValue ;
542
539
private final NamedAnalyzer normalizer ;
543
540
private final boolean eagerGlobalOrdinals ;
544
541
private final FieldValues <String > scriptValues ;
545
542
private final boolean isDimension ;
546
543
private final boolean isSyntheticSource ;
547
- private final IndexMode indexMode ;
548
544
private final IndexSortConfig indexSortConfig ;
549
545
private final boolean hasDocValuesSkipper ;
550
546
private final String originalName ;
@@ -568,36 +564,34 @@ public KeywordFieldType(
568
564
);
569
565
this .eagerGlobalOrdinals = builder .eagerGlobalOrdinals .getValue ();
570
566
this .normalizer = normalizer ;
571
- this .ignoreAbove = builder .ignoreAbove .getValue ();
567
+ this .ignoreAbove = new IgnoreAbove ( builder .ignoreAbove .getValue (), builder . indexMode , builder . indexCreatedVersion );
572
568
this .nullValue = builder .nullValue .getValue ();
573
569
this .scriptValues = builder .scriptValues ();
574
570
this .isDimension = builder .dimension .getValue ();
575
571
this .isSyntheticSource = isSyntheticSource ;
576
- this .indexMode = builder .indexMode ;
577
572
this .indexSortConfig = builder .indexSortConfig ;
578
573
this .hasDocValuesSkipper = DocValuesSkipIndexType .NONE .equals (fieldType .docValuesSkipIndexType ()) == false ;
579
574
this .originalName = isSyntheticSource ? name + "._original" : null ;
580
575
}
581
576
577
+ public KeywordFieldType (String name ) {
578
+ this (name , true , true , Collections .emptyMap ());
579
+ }
580
+
582
581
public KeywordFieldType (String name , boolean isIndexed , boolean hasDocValues , Map <String , String > meta ) {
583
582
super (name , isIndexed , false , hasDocValues , TextSearchInfo .SIMPLE_MATCH_ONLY , meta );
584
583
this .normalizer = Lucene .KEYWORD_ANALYZER ;
585
- this .ignoreAbove = Integer . MAX_VALUE ;
584
+ this .ignoreAbove = IGNORE_ABOVE_DEFAULT ;
586
585
this .nullValue = null ;
587
586
this .eagerGlobalOrdinals = false ;
588
587
this .scriptValues = null ;
589
588
this .isDimension = false ;
590
589
this .isSyntheticSource = false ;
591
- this .indexMode = IndexMode .STANDARD ;
592
590
this .indexSortConfig = null ;
593
591
this .hasDocValuesSkipper = false ;
594
592
this .originalName = null ;
595
593
}
596
594
597
- public KeywordFieldType (String name ) {
598
- this (name , true , true , Collections .emptyMap ());
599
- }
600
-
601
595
public KeywordFieldType (String name , FieldType fieldType ) {
602
596
super (
603
597
name ,
@@ -608,13 +602,12 @@ public KeywordFieldType(String name, FieldType fieldType) {
608
602
Collections .emptyMap ()
609
603
);
610
604
this .normalizer = Lucene .KEYWORD_ANALYZER ;
611
- this .ignoreAbove = Integer . MAX_VALUE ;
605
+ this .ignoreAbove = IGNORE_ABOVE_DEFAULT ;
612
606
this .nullValue = null ;
613
607
this .eagerGlobalOrdinals = false ;
614
608
this .scriptValues = null ;
615
609
this .isDimension = false ;
616
610
this .isSyntheticSource = false ;
617
- this .indexMode = IndexMode .STANDARD ;
618
611
this .indexSortConfig = null ;
619
612
this .hasDocValuesSkipper = DocValuesSkipIndexType .NONE .equals (fieldType .docValuesSkipIndexType ()) == false ;
620
613
this .originalName = null ;
@@ -623,13 +616,12 @@ public KeywordFieldType(String name, FieldType fieldType) {
623
616
public KeywordFieldType (String name , NamedAnalyzer analyzer ) {
624
617
super (name , true , false , true , textSearchInfo (Defaults .FIELD_TYPE , null , analyzer , analyzer ), Collections .emptyMap ());
625
618
this .normalizer = Lucene .KEYWORD_ANALYZER ;
626
- this .ignoreAbove = Integer . MAX_VALUE ;
619
+ this .ignoreAbove = IGNORE_ABOVE_DEFAULT ;
627
620
this .nullValue = null ;
628
621
this .eagerGlobalOrdinals = false ;
629
622
this .scriptValues = null ;
630
623
this .isDimension = false ;
631
624
this .isSyntheticSource = false ;
632
- this .indexMode = IndexMode .STANDARD ;
633
625
this .indexSortConfig = null ;
634
626
this .hasDocValuesSkipper = false ;
635
627
this .originalName = null ;
@@ -938,10 +930,7 @@ protected String parseSourceValue(Object value) {
938
930
}
939
931
940
932
private String applyIgnoreAboveAndNormalizer (String value ) {
941
- if (value .length () > ignoreAbove ) {
942
- return null ;
943
- }
944
-
933
+ if (ignoreAbove .isIgnored (value )) return null ;
945
934
return normalizeValue (normalizer (), name (), value );
946
935
}
947
936
@@ -1060,7 +1049,7 @@ public CollapseType collapseType() {
1060
1049
1061
1050
/** Values that have more chars than the return value of this method will
1062
1051
* be skipped at parsing time. */
1063
- public int ignoreAbove () {
1052
+ public IgnoreAbove ignoreAbove () {
1064
1053
return ignoreAbove ;
1065
1054
}
1066
1055
@@ -1078,10 +1067,6 @@ public boolean hasNormalizer() {
1078
1067
return normalizer != Lucene .KEYWORD_ANALYZER ;
1079
1068
}
1080
1069
1081
- public IndexMode getIndexMode () {
1082
- return indexMode ;
1083
- }
1084
-
1085
1070
public IndexSortConfig getIndexSortConfig () {
1086
1071
return indexSortConfig ;
1087
1072
}
@@ -1216,7 +1201,7 @@ private boolean indexValue(DocumentParserContext context, XContentString value)
1216
1201
return false ;
1217
1202
}
1218
1203
1219
- if (value . stringLength () > fieldType ().ignoreAbove ()) {
1204
+ if (fieldType ().ignoreAbove (). isIgnored ( value )) {
1220
1205
context .addIgnoredField (fullPath ());
1221
1206
if (isSyntheticSource ) {
1222
1207
// Save a copy of the field so synthetic source can load it
@@ -1385,7 +1370,7 @@ protected BytesRef preserve(BytesRef value) {
1385
1370
}
1386
1371
}
1387
1372
1388
- if (fieldType ().ignoreAbove != Integer . MAX_VALUE ) {
1373
+ if (fieldType ().ignoreAbove . isSet () ) {
1389
1374
layers .add (new CompositeSyntheticFieldLoader .StoredFieldLayer (originalName ) {
1390
1375
@ Override
1391
1376
protected void writeValue (Object value , XContentBuilder b ) throws IOException {
0 commit comments