Skip to content

Commit 85f00a4

Browse files
fix: make methods static and update javadoc
1 parent efad1cd commit 85f00a4

File tree

1 file changed

+17
-23
lines changed

1 file changed

+17
-23
lines changed

server/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -443,52 +443,46 @@ private FieldType resolveFieldType(
443443
) {
444444
if (useDocValuesSparseIndex
445445
&& indexCreatedVersion.onOrAfter(IndexVersions.HOSTNAME_DOC_VALUES_SPARSE_INDEX)
446-
&& shouldUseDocValuesSparseIndex(indexSortConfig, indexMode, fullFieldName)) {
446+
&& shouldUseDocValuesSparseIndex(hasDocValues.getValue(), indexSortConfig, indexMode, fullFieldName)) {
447447
return new FieldType(Defaults.FIELD_TYPE_WITH_SKIP_DOC_VALUES);
448448
}
449449
return new FieldType(Defaults.FIELD_TYPE);
450450
}
451451

452452
/**
453-
* Determines whether to use a sparse index representation for doc values.
453+
* Determines whether to use a sparse doc values index for the {@code host.name} field.
454454
*
455-
* <p>If the field is explicitly indexed by setting {@code index: true}, we do not use
456-
* a sparse doc values index but instead rely on the inverted index, as is typically
457-
* the case for keyword fields.</p>
458-
*
459-
* <p>This method checks several conditions to decide if the sparse index format
460-
* should be applied:</p>
455+
* <p>The sparse doc values index is used if all the following conditions are met:</p>
461456
*
462457
* <ul>
463-
* <li>Returns {@code false} immediately if the field is explicitly indexed.</li>
464-
* <li>Ensures the field is not explicitly configured as indexed (i.e., {@code index} has its default value).</li>
465-
* <li>Requires doc values to be enabled.</li>
466-
* <li>Index mode must be {@link IndexMode#LOGSDB}.</li>
467-
* <li>Field name must be {@code host.name}.</li>
468-
* <li>The {@code host.name} field must be a primary sort field.</li>
458+
* <li>Doc values are enabled for the field.</li>
459+
* <li>The index mode is {@link IndexMode#LOGSDB}.</li>
460+
* <li>The field being checked is {@code host.name}.</li>
461+
* <li>The {@code host.name} field is included in the index sort configuration.</li>
469462
* </ul>
470463
*
471-
* <p>Returns {@code true} if all conditions are met, indicating that sparse doc values
472-
* should be used. Otherwise, returns {@code false}.</p>
464+
* <p>If all conditions are met, the method returns {@code true}, indicating that the sparse
465+
* doc values index should be used. Otherwise, it returns {@code false}.</p>
473466
*
474-
* @param indexSortConfig The index sort configuration, used to check primary sorting.
475-
* @param indexMode The mode of the index, which must be {@link IndexMode#LOGSDB}.
467+
* @param hasDocValues Whether doc values are enabled for the field.
468+
* @param indexSortConfig The index sort configuration, used to check if {@code host.name} is a sort field.
469+
* @param indexMode The mode of the index, which must be {@link IndexMode#LOGSDB} for sparse doc values indexing.
476470
* @param fullFieldName The name of the field being checked, which must be {@code host.name}.
477-
* @return {@code true} if sparse doc values should be used, otherwise {@code false}.
471+
* @return {@code true} if the sparse doc values index should be used, otherwise {@code false}.
478472
*/
479-
480-
private boolean shouldUseDocValuesSparseIndex(
473+
private static boolean shouldUseDocValuesSparseIndex(
474+
final boolean hasDocValues,
481475
final IndexSortConfig indexSortConfig,
482476
final IndexMode indexMode,
483477
final String fullFieldName
484478
) {
485-
return hasDocValues.getValue()
479+
return hasDocValues
486480
&& IndexMode.LOGSDB.equals(indexMode)
487481
&& HOST_NAME.equals(fullFieldName)
488482
&& indexSortConfigByHostName(indexSortConfig);
489483
}
490484

491-
private boolean indexSortConfigByHostName(final IndexSortConfig indexSortConfig) {
485+
private static boolean indexSortConfigByHostName(final IndexSortConfig indexSortConfig) {
492486
return indexSortConfig != null && indexSortConfig.hasIndexSort() && indexSortConfig.hasSortOnFiled(HOST_NAME);
493487
}
494488
}

0 commit comments

Comments
 (0)