-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Ignore script fields when size is 0 #31917
Conversation
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.
Hi @Parth-Vader, thanks for opening the PR. Could you also add a unit test for the change you made? I think adding a test case to SearchServiceTests would work. You can take a look at e.g the existing "testMaxScriptFieldsSearch()" which tests something slightly different but covers the same area in the code.
Pinging @elastic/es-search-aggs |
@cbuescher @colings86 Can you have a look at the test? Is it correctly done? Thanks. |
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.
Hi @Parth-Vader, the test already looks quite good in general. However, it currently also passes without your changes in SearchService.java. I think you need to add a script field to searchSourceBuilder, and later you then check that this is ignored when size=0. You can take a look at "testMaxScriptFieldsSearch" (L328) for an example of how to add a dummy script field to the search source.
|
||
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); | ||
searchSourceBuilder.size(0); | ||
try(SearchContext context = service.createContext(new ShardSearchLocalRequest(indexShard.shardId(), 1, SearchType.DEFAULT, |
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.
nit: whitespace after "try"
searchSourceBuilder.size(0); | ||
try(SearchContext context = service.createContext(new ShardSearchLocalRequest(indexShard.shardId(), 1, SearchType.DEFAULT, | ||
searchSourceBuilder, new String[0], false, new AliasFilter(null, Strings.EMPTY_ARRAY), 1.0f, true, null, null))) { | ||
assertEquals(0,context.scriptFields().fields().size()); |
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.
nit: whitespace after comma
@cbuescher Hi, I added a script field, then set the size to zero. Also added the required white spaces. |
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.
Hi @Parth-Vader, thanks for the changes, there are only a couple of very minor formatting changes I'd like you to make if possible. The rest looks great now.
@@ -345,6 +346,26 @@ public void testMaxScriptFieldsSearch() throws IOException { | |||
} | |||
} | |||
|
|||
public void testIgnoreScriptfieldIfSizeZero() throws IOException{ |
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.
nit: please add a whitespace after IOExecption
final IndexShard indexShard = indexService.getShard(0); | ||
|
||
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); | ||
|
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.
nit: pls remove the extra blank lines (at least the double one)
searchSourceBuilder.size(0); | ||
try (SearchContext context = service.createContext(new ShardSearchLocalRequest(indexShard.shardId(), 1, SearchType.DEFAULT, | ||
searchSourceBuilder, new String[0], false, new AliasFilter(null, Strings.EMPTY_ARRAY), 1.0f, true, null, null))) { | ||
assertEquals(0, context.scriptFields().fields().size()); |
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.
nit: please move indentation to the right so it alligns at four spaces in the try-block)
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.
sorry, do you mean shift assertEquals
four spaces backwards?
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.
@Parth-Vader many thanks, LGTM. I will run CI before merging.
@elasticmachine test this please |
@@ -56,6 +56,7 @@ | |||
import org.elasticsearch.search.aggregations.support.ValueType; | |||
import org.elasticsearch.search.builder.SearchSourceBuilder; | |||
import org.elasticsearch.search.fetch.ShardFetchRequest; | |||
import org.elasticsearch.search.fetch.subphase.ScriptFieldsContext; |
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.
Looks like the checkstyle runner doesn't like unused imports, could you remove this line please?
17:52:18 [ant:checkstyle] [ERROR] /var/lib/jenkins/workspace/elastic+elasticsearch+pull-request/server/src/test/java/org/elasticsearch/search/SearchServiceTests.java:59:8: Unused import - org.elasticsearch.search.fetch.subphase.ScriptFieldsContext. [UnusedImports]
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.
My bad. Done!
@elasticmachine test this please |
@Parth-Vader more CI failures, this time due to an old version of master. I took the liberty to merge in current master, hope you don't mind |
This change adds a check so that when parsing the search source, script fields are ignored when the requested search result size is 0. This helps with e.g. clients like Kibana that sends a list of script fields that they may need for convenience, but they don't require any hits. Before this change, user sometimes ran into confusing behaviour, e.g. the script compilation limit to breaking although no hits were requested. Closes #31824
@Parth-Vader thanks again, I merged this to master and the 6.5 branch. |
@cbuescher Thanks for guiding me through this. |
Addresses issue #31824
I have added the condition as discussed.