-
Notifications
You must be signed in to change notification settings - Fork 25.1k
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
Support fetching _tier field value #71379
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8028838
Support fetching _tier values.
jtibshirani b0f38a5
Reorganize metadata fields docs.
jtibshirani f7f4941
Fix checkstyle.
jtibshirani cad81c7
Fix bad refactor in getTierPreference.
jtibshirani 15fe293
Reject non-null formats.
jtibshirani 5c415d6
Merge remote-tracking branch 'upstream/master' into pr
jtibshirani 3da9214
Make sure to handle missing setting.
jtibshirani 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 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 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 |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
import org.apache.lucene.search.Query; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.common.regex.Regex; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.index.mapper.ConstantFieldType; | ||
import org.elasticsearch.index.mapper.KeywordFieldMapper; | ||
import org.elasticsearch.index.mapper.MetadataFieldMapper; | ||
|
@@ -21,6 +22,8 @@ | |
|
||
import java.util.Collections; | ||
|
||
import static java.util.Collections.singletonList; | ||
|
||
public class DataTierFieldMapper extends MetadataFieldMapper { | ||
|
||
public static final String NAME = "_tier"; | ||
|
@@ -52,19 +55,16 @@ protected boolean matches(String pattern, boolean caseInsensitive, SearchExecuti | |
if (caseInsensitive) { | ||
pattern = Strings.toLowercaseAscii(pattern); | ||
} | ||
String tierPreference = DataTierAllocationDecider.INDEX_ROUTING_PREFER_SETTING.get(context.getIndexSettings().getSettings()); | ||
String tierPreference = getTierPreference(context); | ||
if (tierPreference == null) { | ||
return false; | ||
} | ||
// Tier preference can be a comma-delimited list of tiers, ordered by preference | ||
// It was decided we should only test the first of these potentially multiple preferences. | ||
String firstPreference = tierPreference.split(",")[0].trim(); | ||
return Regex.simpleMatch(pattern, firstPreference); | ||
return Regex.simpleMatch(pattern, tierPreference); | ||
} | ||
|
||
@Override | ||
public Query existsQuery(SearchExecutionContext context) { | ||
String tierPreference = DataTierAllocationDecider.INDEX_ROUTING_PREFER_SETTING.get(context.getIndexSettings().getSettings()); | ||
String tierPreference = getTierPreference(context); | ||
if (tierPreference == null) { | ||
return new MatchNoDocsQuery(); | ||
} | ||
|
@@ -73,7 +73,21 @@ public Query existsQuery(SearchExecutionContext context) { | |
|
||
@Override | ||
public ValueFetcher valueFetcher(SearchExecutionContext context, String format) { | ||
throw new UnsupportedOperationException("Cannot fetch values for internal field [" + name() + "]."); | ||
String tierPreference = getTierPreference(context); | ||
return lookup -> singletonList(tierPreference); | ||
} | ||
|
||
private String getTierPreference(SearchExecutionContext context) { | ||
Settings settings = context.getIndexSettings().getSettings(); | ||
String value = DataTierAllocationDecider.INDEX_ROUTING_PREFER_SETTING.get(context.getIndexSettings().getSettings()); | ||
jtibshirani marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (value == null) { | ||
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 assume this will change after #71439 is in, so keeping this comment here for now just to recheck |
||
return null; | ||
} | ||
|
||
// Tier preference can be a comma-delimited list of tiers, ordered by preference | ||
// It was decided we should only test the first of these potentially multiple preferences. | ||
return value.split(",")[0].trim(); | ||
} | ||
} | ||
|
||
|
This file contains 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.
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.
I just noticed this doesn't handle a missing/ empty setting correctly. I'll push a fix.
Update: while writing tests I noticed we don't handle this correctly and opened #71439. I'll return to this PR once that is merged.