-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Provide access to _type in 5.x indices #83195
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ff6f44f
Auto-convert old mappings
ywelsch 05e5183
do mapping-related transformations later
ywelsch 22231a3
somefixes
ywelsch 1b29c63
Access _type in archive data
ywelsch 5671b37
Merge remote-tracking branch 'elastic/master' into access-type-in-arc…
ywelsch 9b9801a
fix
ywelsch 460109f
more
ywelsch 13cdfa5
abs
ywelsch 0acde08
remove dead code
ywelsch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
server/src/main/java/org/elasticsearch/index/mapper/LegacyTypeFieldMapper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.index.mapper; | ||
|
||
import org.apache.lucene.document.FieldType; | ||
import org.apache.lucene.document.SortedSetDocValuesField; | ||
import org.apache.lucene.index.IndexOptions; | ||
import org.apache.lucene.sandbox.search.DocValuesTermsQuery; | ||
import org.apache.lucene.search.Query; | ||
import org.apache.lucene.util.BytesRef; | ||
import org.elasticsearch.common.lucene.Lucene; | ||
import org.elasticsearch.index.query.SearchExecutionContext; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
|
||
/** | ||
* Field mapper to access the legacy _type that existed in Elasticsearch 5 | ||
*/ | ||
public class LegacyTypeFieldMapper extends MetadataFieldMapper { | ||
|
||
public static final String NAME = "_type"; | ||
|
||
public static final String CONTENT_TYPE = "_type"; | ||
|
||
private static final LegacyTypeFieldMapper INSTANCE = new LegacyTypeFieldMapper(); | ||
|
||
public static final TypeParser PARSER = new FixedTypeParser(c -> INSTANCE); | ||
|
||
protected LegacyTypeFieldMapper() { | ||
super(new LegacyTypeFieldType(), Lucene.KEYWORD_ANALYZER); | ||
} | ||
|
||
public static class Defaults { | ||
|
||
public static final FieldType FIELD_TYPE = new FieldType(); | ||
public static final FieldType NESTED_FIELD_TYPE; | ||
|
||
static { | ||
FIELD_TYPE.setTokenized(false); | ||
FIELD_TYPE.setIndexOptions(IndexOptions.DOCS); | ||
FIELD_TYPE.setStored(true); | ||
FIELD_TYPE.setOmitNorms(true); | ||
FIELD_TYPE.freeze(); | ||
|
||
NESTED_FIELD_TYPE = new FieldType(); | ||
NESTED_FIELD_TYPE.setTokenized(false); | ||
NESTED_FIELD_TYPE.setIndexOptions(IndexOptions.DOCS); | ||
NESTED_FIELD_TYPE.setStored(false); | ||
NESTED_FIELD_TYPE.setOmitNorms(true); | ||
NESTED_FIELD_TYPE.freeze(); | ||
} | ||
} | ||
|
||
static final class LegacyTypeFieldType extends TermBasedFieldType { | ||
|
||
LegacyTypeFieldType() { | ||
super(NAME, false, true, true, TextSearchInfo.SIMPLE_MATCH_ONLY, Collections.emptyMap()); | ||
} | ||
|
||
@Override | ||
public String typeName() { | ||
return CONTENT_TYPE; | ||
} | ||
|
||
@Override | ||
public boolean isSearchable() { | ||
// The _type field is always searchable. | ||
return true; | ||
} | ||
|
||
@Override | ||
public Query termQuery(Object value, SearchExecutionContext context) { | ||
return SortedSetDocValuesField.newSlowExactQuery(name(), indexedValueForSearch(value)); | ||
} | ||
|
||
@Override | ||
public Query termsQuery(Collection<?> values, SearchExecutionContext context) { | ||
BytesRef[] bytesRefs = values.stream().map(this::indexedValueForSearch).toArray(BytesRef[]::new); | ||
return new DocValuesTermsQuery(name(), bytesRefs); | ||
} | ||
|
||
@Override | ||
public Query rangeQuery( | ||
Object lowerTerm, | ||
Object upperTerm, | ||
boolean includeLower, | ||
boolean includeUpper, | ||
SearchExecutionContext context | ||
) { | ||
return SortedSetDocValuesField.newSlowRangeQuery( | ||
name(), | ||
lowerTerm == null ? null : indexedValueForSearch(lowerTerm), | ||
upperTerm == null ? null : indexedValueForSearch(upperTerm), | ||
includeLower, | ||
includeUpper | ||
); | ||
} | ||
|
||
@Override | ||
public boolean mayExistInIndex(SearchExecutionContext context) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public ValueFetcher valueFetcher(SearchExecutionContext context, String format) { | ||
return new StoredValueFetcher(context.lookup(), NAME); | ||
} | ||
} | ||
|
||
@Override | ||
protected String contentType() { | ||
return CONTENT_TYPE; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.