Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected boolean matches(String pattern, boolean caseInsensitive, SearchExecuti
pattern = Strings.toLowercaseAscii(pattern);
}
String tierPreference = DataTierAllocationDecider.INDEX_ROUTING_PREFER_SETTING.get(context.getIndexSettings().getSettings());
if (tierPreference == null) {
if (Strings.hasText(tierPreference) == false) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is a little unusual, but it matches how we test for the setting in other places like DataTierAllocationDecider.

return false;
}
// Tier preference can be a comma-delimited list of tiers, ordered by preference
Expand All @@ -65,7 +65,7 @@ protected boolean matches(String pattern, boolean caseInsensitive, SearchExecuti
@Override
public Query existsQuery(SearchExecutionContext context) {
String tierPreference = DataTierAllocationDecider.INDEX_ROUTING_PREFER_SETTING.get(context.getIndexSettings().getSettings());
if (tierPreference == null) {
if (Strings.hasText(tierPreference) == false) {
return new MatchNoDocsQuery();
}
return new MatchAllDocsQuery();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,34 @@ public void testWildcardQuery() {
assertEquals(new MatchAllDocsQuery(), ft.wildcardQuery("Data_Warm", null, true, createContext()));
assertEquals(new MatchNoDocsQuery(), ft.wildcardQuery("Data_Warm", null, false, createContext()));
assertEquals(new MatchNoDocsQuery(), ft.wildcardQuery("noSuchRole", null, createContext()));

assertEquals(new MatchNoDocsQuery(), ft.wildcardQuery("data_*", null, createContextWithoutSetting()));
assertEquals(new MatchNoDocsQuery(), ft.wildcardQuery("*", null, createContextWithoutSetting()));
}

public void testTermQuery() {
MappedFieldType ft = DataTierFieldMapper.DataTierFieldType.INSTANCE;
assertEquals(new MatchAllDocsQuery(), ft.termQuery("data_warm", createContext()));
assertEquals(new MatchNoDocsQuery(), ft.termQuery("data_hot", createContext()));
assertEquals(new MatchNoDocsQuery(), ft.termQuery("noSuchRole", createContext()));

assertEquals(new MatchNoDocsQuery(), ft.termQuery("data_warm", createContextWithoutSetting()));
assertEquals(new MatchNoDocsQuery(), ft.termQuery("", createContextWithoutSetting()));
}

public void testTermsQuery() {
MappedFieldType ft = DataTierFieldMapper.DataTierFieldType.INSTANCE;
assertEquals(new MatchAllDocsQuery(), ft.termsQuery(Arrays.asList("data_warm"), createContext()));
assertEquals(new MatchNoDocsQuery(), ft.termsQuery(Arrays.asList("data_cold", "data_frozen"), createContext()));

assertEquals(new MatchNoDocsQuery(), ft.termsQuery(Arrays.asList("data_warm"), createContextWithoutSetting()));
assertEquals(new MatchNoDocsQuery(), ft.termsQuery(Arrays.asList(""), createContextWithoutSetting()));
}

public void testExistsQuery() {
MappedFieldType ft = DataTierFieldMapper.DataTierFieldType.INSTANCE;
assertEquals(new MatchAllDocsQuery(), ft.existsQuery(createContext()));
assertEquals(new MatchNoDocsQuery(), ft.existsQuery(createContextWithoutSetting()));
}

public void testRegexpQuery() {
Expand Down Expand Up @@ -102,4 +117,18 @@ private SearchExecutionContext createContext() {
emptyMap()
);
}

private SearchExecutionContext createContextWithoutSetting() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe we could re-use the other createContext() method by adding an argument (e.g. a bool flag) to either return a context with- or without the setting?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion, I'll stick with this approach as I find it clearest right now. We can always refactor if these methods grow larger and there's more duplication!

IndexMetadata indexMetadata = IndexMetadata.builder("index")
.settings(Settings.builder()
.put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT)
.build())
.numberOfShards(1)
.numberOfReplicas(0)
.build();
IndexSettings indexSettings = new IndexSettings(indexMetadata, Settings.EMPTY);
return new SearchExecutionContext(0, 0, indexSettings, null, null, null, null, null, null,
xContentRegistry(), writableRegistry(), null, null, System::currentTimeMillis, null,
value -> true, () -> true, null, emptyMap());
}
}