Skip to content
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

Source filtering with wildcards broken when given multiple patterns #5133

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ private static void filter(Map<String, Object> map, Map<String, Object> into, St
break;
}
pathIsPrefixOfAnInclude = true;
break;
continue;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the actual cause of the issue. +1

}
if (include.startsWith(path)) {
if (include.length() == path.length()) {
Expand All @@ -184,7 +184,7 @@ private static void filter(Map<String, Object> map, Map<String, Object> into, St
} else if (include.length() > path.length() && include.charAt(path.length()) == '.') {
// include might may match deeper paths. Dive deeper.
pathIsPrefixOfAnInclude = true;
break;
continue;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is good for include=a.b.*,a (though highly unlikely to happen in practice). Maybe add a test as well?

}
}
if (Regex.simpleMatch(include, path)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,26 @@ public void testSourceFiltering() {

}

/**
* Test Case for #5132: Source filtering with wildcards broken when given multiple patterns
* https://github.com/elasticsearch/elasticsearch/issues/5132
*/
@Test
public void testSourceWithWildcardFiltering() {
createIndex("test");
ensureGreen();

client().prepareIndex("test", "type1", "1").setSource("field", "value").get();
refresh();

SearchResponse response = client().prepareSearch("test").setFetchSource(new String[]{"*.notexisting","field"}, null).get();
assertThat(response.getHits().getAt(0).getSourceAsString(), notNullValue());
assertThat(response.getHits().getAt(0).getSource().size(), equalTo(1));
assertThat((String) response.getHits().getAt(0).getSource().get("field"), equalTo("value"));

response = client().prepareSearch("test").setFetchSource(new String[]{"field.notexisting.*","field"}, null).get();
assertThat(response.getHits().getAt(0).getSourceAsString(), notNullValue());
assertThat(response.getHits().getAt(0).getSource().size(), equalTo(1));
assertThat((String) response.getHits().getAt(0).getSource().get("field"), equalTo("value"));
}
}