-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Doc values sparse index on _tsid fields #122699
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
25749f4
8a3ecc8
1305b0d
90177e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,17 +46,36 @@ public class TimeSeriesIdFieldMapper extends MetadataFieldMapper { | |
| public static final String NAME = "_tsid"; | ||
| public static final String CONTENT_TYPE = "_tsid"; | ||
| public static final TimeSeriesIdFieldType FIELD_TYPE = new TimeSeriesIdFieldType(); | ||
| public static final TimeSeriesIdFieldMapper INSTANCE = new TimeSeriesIdFieldMapper(); | ||
|
|
||
| private static final TimeSeriesIdFieldMapper INSTANCE_WITHOUT_SKIPPER = new TimeSeriesIdFieldMapper(false); | ||
| private static final TimeSeriesIdFieldMapper INSTANCE_WITH_SKIPPER = new TimeSeriesIdFieldMapper(true); | ||
|
|
||
| public static TimeSeriesIdFieldMapper getInstance(boolean useDocValuesSkipper) { | ||
| if (useDocValuesSkipper) { | ||
| return INSTANCE_WITH_SKIPPER; | ||
| } else { | ||
| return INSTANCE_WITHOUT_SKIPPER; | ||
| } | ||
| } | ||
|
|
||
| public static TimeSeriesIdFieldMapper getInstance(MappingParserContext context) { | ||
| boolean useDocValuesSkipper = context.indexVersionCreated().onOrAfter(IndexVersions.TIME_SERIES_ID_DOC_VALUES_SPARSE_INDEX) | ||
| && context.getIndexSettings().useDocValuesSkipper(); | ||
| return TimeSeriesIdFieldMapper.getInstance(useDocValuesSkipper); | ||
| } | ||
|
|
||
| @Override | ||
| public FieldMapper.Builder getMergeBuilder() { | ||
| return new Builder().init(this); | ||
| return new Builder(this.useDocValuesSkipper).init(this); | ||
| } | ||
|
|
||
| public static class Builder extends MetadataFieldMapper.Builder { | ||
|
|
||
| protected Builder() { | ||
| private final boolean useDocValuesSkipper; | ||
|
|
||
| protected Builder(boolean useDocValuesSkipper) { | ||
| super(NAME); | ||
| this.useDocValuesSkipper = useDocValuesSkipper; | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -66,11 +85,11 @@ protected Parameter<?>[] getParameters() { | |
|
|
||
| @Override | ||
| public TimeSeriesIdFieldMapper build() { | ||
| return INSTANCE; | ||
| return TimeSeriesIdFieldMapper.getInstance(useDocValuesSkipper); | ||
| } | ||
| } | ||
|
|
||
| public static final TypeParser PARSER = new FixedTypeParser(c -> c.getIndexSettings().getMode().timeSeriesIdFieldMapper()); | ||
| public static final TypeParser PARSER = new FixedTypeParser(c -> c.getIndexSettings().getMode().timeSeriesIdFieldMapper(c)); | ||
|
|
||
| public static final class TimeSeriesIdFieldType extends MappedFieldType { | ||
| private TimeSeriesIdFieldType() { | ||
|
|
@@ -115,8 +134,11 @@ public Query termQuery(Object value, SearchExecutionContext context) { | |
| } | ||
| } | ||
|
|
||
| private TimeSeriesIdFieldMapper() { | ||
| private final boolean useDocValuesSkipper; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can avoid passing down index version here. We can set |
||
|
|
||
| private TimeSeriesIdFieldMapper(boolean useDocValuesSkipper) { | ||
| super(FIELD_TYPE); | ||
| this.useDocValuesSkipper = useDocValuesSkipper; | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -135,7 +157,12 @@ public void postParse(DocumentParserContext context) throws IOException { | |
| } else { | ||
| timeSeriesId = routingPathFields.buildHash().toBytesRef(); | ||
| } | ||
| context.doc().add(new SortedDocValuesField(fieldType().name(), timeSeriesId)); | ||
|
|
||
| if (this.useDocValuesSkipper) { | ||
| context.doc().add(SortedDocValuesField.indexedField(fieldType().name(), timeSeriesId)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SortedDocValuesField#indexedField creates a new SortedDocValuesField using a private static FieldType that has the skip index enabled. It's the same as discussed for SortedNumericDocValuesField in #122161 (comment) |
||
| } else { | ||
| context.doc().add(new SortedDocValuesField(fieldType().name(), timeSeriesId)); | ||
| } | ||
|
|
||
| BytesRef uidEncoded = TsidExtractingIdFieldMapper.createField( | ||
| context, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason why this is a singleton constant is to reduce memory usage of
MapperService. Meta field mappers that can be initialized as a constant are a constant. A node can have manyMapperServiceinstances (one per allocated index).I think can just define two singleton instances here and then decide to use which in
IndexMode#timeSeriesIdFieldMapper(...)based on index versions and whether the feature flag is enabled?