@@ -209,7 +209,8 @@ public static final class Builder extends FieldMapper.DimensionBuilder {
209209 private final IndexAnalyzers indexAnalyzers ;
210210 private final ScriptCompiler scriptCompiler ;
211211 private final IndexVersion indexCreatedVersion ;
212- private final boolean useDocValuesSkipper ;
212+ private final boolean enableDocValuesSkipper ;
213+ private final boolean forceDocValuesSkipper ;
213214 private final SourceKeepMode indexSourceKeepMode ;
214215
215216 public Builder (final String name , final MappingParserContext mappingParserContext ) {
@@ -222,6 +223,7 @@ public Builder(final String name, final MappingParserContext mappingParserContex
222223 mappingParserContext .getIndexSettings ().getMode (),
223224 mappingParserContext .getIndexSettings ().getIndexSortConfig (),
224225 USE_DOC_VALUES_SKIPPER .get (mappingParserContext .getSettings ()),
226+ false ,
225227 mappingParserContext .getIndexSettings ().sourceKeepMode ()
226228 );
227229 }
@@ -243,6 +245,7 @@ public Builder(final String name, final MappingParserContext mappingParserContex
243245 IndexMode .STANDARD ,
244246 null ,
245247 false ,
248+ false ,
246249 sourceKeepMode
247250 );
248251 }
@@ -255,7 +258,8 @@ private Builder(
255258 IndexVersion indexCreatedVersion ,
256259 IndexMode indexMode ,
257260 IndexSortConfig indexSortConfig ,
258- boolean useDocValuesSkipper ,
261+ boolean enableDocValuesSkipper ,
262+ boolean forceDocValuesSkipper ,
259263 SourceKeepMode indexSourceKeepMode
260264 ) {
261265 super (name );
@@ -293,14 +297,36 @@ private Builder(
293297 });
294298 this .indexSortConfig = indexSortConfig ;
295299 this .indexMode = indexMode ;
296- this .useDocValuesSkipper = useDocValuesSkipper ;
300+ this .enableDocValuesSkipper = enableDocValuesSkipper ;
301+ this .forceDocValuesSkipper = forceDocValuesSkipper ;
297302 this .indexSourceKeepMode = indexSourceKeepMode ;
298303 }
299304
300305 public Builder (String name , IndexVersion indexCreatedVersion ) {
301306 this (name , null , ScriptCompiler .NONE , Integer .MAX_VALUE , indexCreatedVersion , SourceKeepMode .NONE );
302307 }
303308
309+ public static Builder buildWithDocValuesSkipper (
310+ String name ,
311+ IndexMode indexMode ,
312+ IndexVersion indexCreatedVersion ,
313+ boolean enableDocValuesSkipper
314+ ) {
315+ return new Builder (
316+ name ,
317+ null ,
318+ ScriptCompiler .NONE ,
319+ Integer .MAX_VALUE ,
320+ indexCreatedVersion ,
321+ indexMode ,
322+ // Sort config is used to decide if DocValueSkippers can be used. Since skippers are forced, a sort config is not needed.
323+ null ,
324+ enableDocValuesSkipper ,
325+ true ,
326+ SourceKeepMode .NONE
327+ );
328+ }
329+
304330 public Builder ignoreAbove (int ignoreAbove ) {
305331 this .ignoreAbove .setValue (ignoreAbove );
306332 return this ;
@@ -422,7 +448,9 @@ private KeywordFieldType buildFieldType(MapperBuilderContext context, FieldType
422448 @ Override
423449 public KeywordFieldMapper build (MapperBuilderContext context ) {
424450 FieldType fieldtype = resolveFieldType (
425- useDocValuesSkipper ,
451+ enableDocValuesSkipper ,
452+ forceDocValuesSkipper ,
453+ hasDocValues ,
426454 indexCreatedVersion ,
427455 indexSortConfig ,
428456 indexMode ,
@@ -460,24 +488,30 @@ public KeywordFieldMapper build(MapperBuilderContext context) {
460488 buildFieldType (context , fieldtype ),
461489 builderParams (this , context ),
462490 context .isSourceSynthetic (),
463- useDocValuesSkipper ,
464491 this ,
465492 offsetsFieldName ,
466493 indexSourceKeepMode
467494 );
468495 }
469496
470- private FieldType resolveFieldType (
471- final boolean useDocValuesSkipper ,
497+ private static FieldType resolveFieldType (
498+ final boolean enableDocValuesSkipper ,
499+ final boolean forceDocValuesSkipper ,
500+ final Parameter <Boolean > hasDocValues ,
472501 final IndexVersion indexCreatedVersion ,
473502 final IndexSortConfig indexSortConfig ,
474503 final IndexMode indexMode ,
475504 final String fullFieldName
476505 ) {
477- if (useDocValuesSkipper
478- && indexCreatedVersion .onOrAfter (IndexVersions .HOSTNAME_DOC_VALUES_SPARSE_INDEX )
479- && shouldUseDocValuesSkipper (hasDocValues .getValue (), indexSortConfig , indexMode , fullFieldName )) {
480- return new FieldType (Defaults .FIELD_TYPE_WITH_SKIP_DOC_VALUES );
506+ if (enableDocValuesSkipper ) {
507+ if (forceDocValuesSkipper ) {
508+ assert hasDocValues .getValue ();
509+ return new FieldType (Defaults .FIELD_TYPE_WITH_SKIP_DOC_VALUES );
510+ }
511+ if (indexCreatedVersion .onOrAfter (IndexVersions .HOSTNAME_DOC_VALUES_SPARSE_INDEX )
512+ && shouldUseDocValuesSkipper (hasDocValues .getValue (), indexSortConfig , indexMode , fullFieldName )) {
513+ return new FieldType (Defaults .FIELD_TYPE_WITH_SKIP_DOC_VALUES );
514+ }
481515 }
482516 return new FieldType (Defaults .FIELD_TYPE );
483517 }
@@ -1088,7 +1122,8 @@ public String originalName() {
10881122 private final int ignoreAboveDefault ;
10891123 private final IndexMode indexMode ;
10901124 private final IndexSortConfig indexSortConfig ;
1091- private final boolean useDocValuesSkipper ;
1125+ private final boolean enableDocValuesSkipper ;
1126+ private final boolean forceDocValuesSkipper ;
10921127 private final String offsetsFieldName ;
10931128 private final SourceKeepMode indexSourceKeepMode ;
10941129 private final String originalName ;
@@ -1099,7 +1134,6 @@ private KeywordFieldMapper(
10991134 KeywordFieldType mappedFieldType ,
11001135 BuilderParams builderParams ,
11011136 boolean isSyntheticSource ,
1102- boolean useDocValuesSkipper ,
11031137 Builder builder ,
11041138 String offsetsFieldName ,
11051139 SourceKeepMode indexSourceKeepMode
@@ -1120,7 +1154,8 @@ private KeywordFieldMapper(
11201154 this .ignoreAboveDefault = builder .ignoreAboveDefault ;
11211155 this .indexMode = builder .indexMode ;
11221156 this .indexSortConfig = builder .indexSortConfig ;
1123- this .useDocValuesSkipper = useDocValuesSkipper ;
1157+ this .enableDocValuesSkipper = builder .enableDocValuesSkipper ;
1158+ this .forceDocValuesSkipper = builder .forceDocValuesSkipper ;
11241159 this .offsetsFieldName = offsetsFieldName ;
11251160 this .indexSourceKeepMode = indexSourceKeepMode ;
11261161 this .originalName = mappedFieldType .originalName ();
@@ -1219,7 +1254,7 @@ private boolean indexValue(DocumentParserContext context, XContentString value)
12191254 throw new IllegalArgumentException (msg );
12201255 }
12211256
1222- Field field = new KeywordField ( fieldType (). name (), binaryValue , fieldType );
1257+ Field field = buildKeywordField ( binaryValue );
12231258 context .doc ().add (field );
12241259
12251260 if (fieldType ().hasDocValues () == false && fieldType .omitNorms ()) {
@@ -1276,11 +1311,16 @@ public FieldMapper.Builder getMergeBuilder() {
12761311 indexCreatedVersion ,
12771312 indexMode ,
12781313 indexSortConfig ,
1279- useDocValuesSkipper ,
1314+ enableDocValuesSkipper ,
1315+ forceDocValuesSkipper ,
12801316 indexSourceKeepMode
12811317 ).dimension (fieldType ().isDimension ()).init (this );
12821318 }
12831319
1320+ public Field buildKeywordField (BytesRef binaryValue ) {
1321+ return new KeywordField (fieldType ().name (), binaryValue , fieldType );
1322+ }
1323+
12841324 @ Override
12851325 public void doValidate (MappingLookup lookup ) {
12861326 if (fieldType ().isDimension () && null != lookup .nestedLookup ().getNestedParent (fullPath ())) {
0 commit comments