SecurityIndexSearcherWrapper should build a filter instead of a query (elastic/elasticsearch#4953)

The SecurityIndexSearcherWrapper was calling toQuery instead of toFilter, which in certain cases can trip the max
clause count check for a boolean query. The same query works fine as a filter and that is what users would expect when
using the query for document level security.

Original commit: elastic/x-pack-elasticsearch@40330636ec
This commit is contained in:
Jay Modi 2017-02-10 10:37:35 -05:00 committed by GitHub
parent 406741c2f8
commit 51cff2f3e4
2 changed files with 2 additions and 2 deletions

View File

@ -140,7 +140,7 @@ public class SecurityIndexSearcherWrapper extends IndexSearcherWrapper {
QueryBuilder queryBuilder = queryShardContext.newParseContext(parser).parseInnerQueryBuilder(); QueryBuilder queryBuilder = queryShardContext.newParseContext(parser).parseInnerQueryBuilder();
verifyRoleQuery(queryBuilder); verifyRoleQuery(queryBuilder);
failIfQueryUsesClient(scriptService, queryBuilder, queryShardContext); failIfQueryUsesClient(scriptService, queryBuilder, queryShardContext);
ParsedQuery parsedQuery = queryShardContext.toQuery(queryBuilder); ParsedQuery parsedQuery = queryShardContext.toFilter(queryBuilder);
filter.add(parsedQuery.query(), SHOULD); filter.add(parsedQuery.query(), SHOULD);
} }
} }

View File

@ -146,7 +146,7 @@ public class SecurityIndexSearcherWrapperIntegrationTests extends ESTestCase {
ParsedQuery parsedQuery = new ParsedQuery(new TermQuery(new Term("field", values[i]))); ParsedQuery parsedQuery = new ParsedQuery(new TermQuery(new Term("field", values[i])));
when(queryShardContext.newParseContext(anyParser())).thenReturn(queryParseContext); when(queryShardContext.newParseContext(anyParser())).thenReturn(queryParseContext);
when(queryParseContext.parseInnerQueryBuilder()).thenReturn(new TermQueryBuilder("field", values[i])); when(queryParseContext.parseInnerQueryBuilder()).thenReturn(new TermQueryBuilder("field", values[i]));
when(queryShardContext.toQuery(new TermsQueryBuilder("field", values[i]))).thenReturn(parsedQuery); when(queryShardContext.toFilter(new TermsQueryBuilder("field", values[i]))).thenReturn(parsedQuery);
DirectoryReader wrappedDirectoryReader = wrapper.wrap(directoryReader); DirectoryReader wrappedDirectoryReader = wrapper.wrap(directoryReader);
IndexSearcher indexSearcher = wrapper.wrap(new IndexSearcher(wrappedDirectoryReader)); IndexSearcher indexSearcher = wrapper.wrap(new IndexSearcher(wrappedDirectoryReader));