-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Add text field support to archive indices #86591
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 22 commits
354624f
56d0e7b
bbaa535
31d37af
eb30319
b8ffa8d
0d40083
b7dd421
7f590ad
8d03678
c33e835
ac09d02
e99a176
c0e508f
55c462c
97c49e2
d28cea8
0415143
7ef03bd
9d4b7d0
1da6dd1
948f2a9
56d391c
6780c48
604d70c
817b5a3
80419e3
1f96dfc
334efdf
3033e12
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 |
|---|---|---|
|
|
@@ -50,6 +50,7 @@ | |
| import org.elasticsearch.common.lucene.Lucene; | ||
| import org.elasticsearch.common.lucene.search.AutomatonQueries; | ||
| import org.elasticsearch.common.lucene.search.MultiPhrasePrefixQuery; | ||
| import org.elasticsearch.common.unit.Fuzziness; | ||
| import org.elasticsearch.common.xcontent.support.XContentMapValues; | ||
| import org.elasticsearch.index.analysis.AnalyzerScope; | ||
| import org.elasticsearch.index.analysis.IndexAnalyzers; | ||
|
|
@@ -278,7 +279,8 @@ public Builder(String name, Version indexCreatedVersion, IndexAnalyzers indexAna | |
| this.analyzers = new TextParams.Analyzers( | ||
| indexAnalyzers, | ||
| m -> ((TextFieldMapper) m).indexAnalyzer, | ||
| m -> (((TextFieldMapper) m).positionIncrementGap) | ||
| m -> (((TextFieldMapper) m).positionIncrementGap), | ||
| indexCreatedVersion | ||
| ); | ||
| } | ||
|
|
||
|
|
@@ -329,7 +331,7 @@ protected List<Parameter<?>> getParameters() { | |
| ); | ||
| } | ||
|
|
||
| private TextFieldType buildFieldType(FieldType fieldType, MapperBuilderContext context) { | ||
| private TextFieldType buildFieldType(FieldType fieldType, MapperBuilderContext context, Version indexCreatedVersion) { | ||
| NamedAnalyzer searchAnalyzer = analyzers.getSearchAnalyzer(); | ||
| NamedAnalyzer searchQuoteAnalyzer = analyzers.getSearchQuoteAnalyzer(); | ||
| if (analyzers.positionIncrementGap.isConfigured()) { | ||
|
|
@@ -340,7 +342,12 @@ private TextFieldType buildFieldType(FieldType fieldType, MapperBuilderContext c | |
| } | ||
| } | ||
| TextSearchInfo tsi = new TextSearchInfo(fieldType, similarity.getValue(), searchAnalyzer, searchQuoteAnalyzer); | ||
| TextFieldType ft = new TextFieldType(context.buildFullName(name), index.getValue(), store.getValue(), tsi, meta.getValue()); | ||
| TextFieldType ft; | ||
| if (indexCreatedVersion.isLegacyIndexVersion()) { | ||
| ft = new ConstantScoreTextFieldType(context.buildFullName(name), index.getValue(), store.getValue(), tsi, meta.getValue()); | ||
| } else { | ||
| ft = new TextFieldType(context.buildFullName(name), index.getValue(), store.getValue(), tsi, meta.getValue()); | ||
| } | ||
| ft.eagerGlobalOrdinals = eagerGlobalOrdinals.getValue(); | ||
| if (fieldData.getValue()) { | ||
| ft.setFielddata(true, freqFilter.getValue()); | ||
|
|
@@ -430,7 +437,7 @@ public Map<String, NamedAnalyzer> indexAnalyzers(String name, SubFieldInfo phras | |
| @Override | ||
| public TextFieldMapper build(MapperBuilderContext context) { | ||
| FieldType fieldType = TextParams.buildFieldType(index, store, indexOptions, norms, termVectors); | ||
| TextFieldType tft = buildFieldType(fieldType, context); | ||
| TextFieldType tft = buildFieldType(fieldType, context, indexCreatedVersion); | ||
| SubFieldInfo phraseFieldInfo = buildPhraseInfo(fieldType, tft); | ||
| SubFieldInfo prefixFieldInfo = buildPrefixInfo(context, fieldType, tft); | ||
| MultiFields multiFields = multiFieldsBuilder.build(this, context); | ||
|
|
@@ -453,7 +460,12 @@ public TextFieldMapper build(MapperBuilderContext context) { | |
| } | ||
| } | ||
|
|
||
| public static final TypeParser PARSER = new TypeParser((n, c) -> new Builder(n, c.indexVersionCreated(), c.getIndexAnalyzers())); | ||
| private static final Version MINIMUM_COMPATIBILITY_VERSION = Version.fromString("5.0.0"); | ||
|
|
||
| public static final TypeParser PARSER = new TypeParser( | ||
| (n, c) -> new Builder(n, c.indexVersionCreated(), c.getIndexAnalyzers()), | ||
| MINIMUM_COMPATIBILITY_VERSION | ||
| ); | ||
|
|
||
| private static class PhraseWrappedAnalyzer extends AnalyzerWrapper { | ||
|
|
||
|
|
@@ -897,6 +909,78 @@ public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName, S | |
|
|
||
| } | ||
|
|
||
| public static class ConstantScoreTextFieldType extends TextFieldType { | ||
|
|
||
| public ConstantScoreTextFieldType(String name, boolean indexed, boolean stored, TextSearchInfo tsi, Map<String, String> meta) { | ||
| super(name, indexed, stored, tsi, meta); | ||
| } | ||
|
|
||
| public ConstantScoreTextFieldType(String name) { | ||
| this( | ||
| name, | ||
| true, | ||
| false, | ||
| new TextSearchInfo(Defaults.FIELD_TYPE, null, Lucene.STANDARD_ANALYZER, Lucene.STANDARD_ANALYZER), | ||
| Collections.emptyMap() | ||
| ); | ||
| } | ||
|
|
||
| public ConstantScoreTextFieldType(String name, boolean indexed, boolean stored, Map<String, String> meta) { | ||
| this( | ||
| name, | ||
| indexed, | ||
| stored, | ||
| new TextSearchInfo(Defaults.FIELD_TYPE, null, Lucene.STANDARD_ANALYZER, Lucene.STANDARD_ANALYZER), | ||
| meta | ||
| ); | ||
| } | ||
|
|
||
| @Override | ||
| public Query termQuery(Object value, SearchExecutionContext context) { | ||
| // Disable scoring | ||
| return new ConstantScoreQuery(super.termQuery(value, context)); | ||
| } | ||
|
|
||
| @Override | ||
| public Query fuzzyQuery( | ||
| Object value, | ||
| Fuzziness fuzziness, | ||
| int prefixLength, | ||
| int maxExpansions, | ||
| boolean transpositions, | ||
| SearchExecutionContext context | ||
| ) { | ||
| // Disable scoring | ||
| return new ConstantScoreQuery(super.fuzzyQuery(value, fuzziness, prefixLength, maxExpansions, transpositions, context)); | ||
| } | ||
|
|
||
| @Override | ||
| public Query phraseQuery(TokenStream stream, int slop, boolean enablePosIncrements, SearchExecutionContext queryShardContext) | ||
| throws IOException { | ||
| // Disable scoring | ||
| return new ConstantScoreQuery(super.phraseQuery(stream, slop, enablePosIncrements, queryShardContext)); | ||
| } | ||
|
|
||
| @Override | ||
| public Query multiPhraseQuery( | ||
| TokenStream stream, | ||
| int slop, | ||
| boolean enablePositionIncrements, | ||
| SearchExecutionContext queryShardContext | ||
| ) throws IOException { | ||
| // Disable scoring | ||
| return new ConstantScoreQuery(super.multiPhraseQuery(stream, slop, enablePositionIncrements, queryShardContext)); | ||
| } | ||
|
|
||
| @Override | ||
| public Query phrasePrefixQuery(TokenStream stream, int slop, int maxExpansions, SearchExecutionContext queryShardContext) | ||
| throws IOException { | ||
| // Disable scoring | ||
| return new ConstantScoreQuery(super.phrasePrefixQuery(stream, slop, maxExpansions, queryShardContext)); | ||
| } | ||
|
|
||
|
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. Span prefix queries will do something weird here, won't they? But then span prefix queries are kind of weird in any case. I think they're enough of an edge case that we can override 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 agree that we don't need to support them. I've pushed 604d70c but I'm not sure how to add a test for it (I couldn't find existing tests that exercise this method). 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. It looks as though the two places it would be used are 1) a prefix query wrapped in a span multiterm query, which can be replaced by an interval query; and 2) a match_phrase_prefix query that uses multiterm synonyms, which will get factored away when we rework things to use QueryBuilders properly. So I think we can happily just throw an exception here and not worry about it further :) |
||
| } | ||
|
|
||
| private final Version indexCreatedVersion; | ||
| private final boolean index; | ||
| private final boolean store; | ||
|
|
||
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 changes in this class revert the changes made in #85059, as we now validate against a MapperService with all analyzers configured when restoring the legacy index in
RestoreService. The reason for doing it this way now is that it provides better error messages on restore, but also handles a tricky situation where the Mapping returned by these methods here would have their analyzer settings misconfigured as checkMappingsCompatibility would not create a proper environment with actual analyzers configured.