Throw if two inner_hits have the same name#37645
Conversation
|
Pinging @elastic/es-search |
jimczi
left a comment
There was a problem hiding this comment.
Thanks @dvehar , the change looks great.
I left some comments regarding the unit tests, we also need an integration test that check that setting two inner hits with the same name throws an exception during the execution of the query. Can you add one in NestedIT for instance ?
There was a problem hiding this comment.
Can you use IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> queryBuilder.extractInnerHitBuilders(Collections.singletonMap("some_name", null)); instead ?
There was a problem hiding this comment.
Can you change the test to use the static function InnerHitContextBuilder#extractInnerHits to retrieve the builders ? It's the function we use to build the inner hits map.
|
I'll work on the integration test soon |
|
@jimczi Could you provide some guidance as to what my test case should look like? I've tried a few things but can't seem to get NestedQueryBuilder::extractInnerHitBuilders to be called. I'll keep working on it meanwhile. |
I tested locally and the following query failed with the check that you added in this pr: You should not test aggregations, that's a different issue but we should not allow inner hits in the filter aggregations. They are not supported there so extractInnerHitBuilders is never called. |
aebb18b to
b205f9d
Compare
|
@jimczi looks good? |
There was a problem hiding this comment.
we should use the same format for the message than the option in the request, can you change innerHits to [inner_hits] ?
There was a problem hiding this comment.
Same here, innerHits-> [inner_hits]
There was a problem hiding this comment.
If innerHitBuilder.getName() is null we use the type as the name (see below). Can you build the name first and check in the inner hits map with the inferred one ?:
String name = innerHitBuilder.getName() != null ? innerHitBuilder.getName() : type;
if (innerHits.containsKey(name)) {
...
There was a problem hiding this comment.
See above, we should check with the inferred name as well if innerHitBuilder.getName is null.
There was a problem hiding this comment.
here the path is used if the name is null, can you infer the name first and then check inside the map ?
There was a problem hiding this comment.
This test should fail, we use the path of the nested field as the name when it is not provided so we should also detect the duplication here.
There was a problem hiding this comment.
Ah ok. When you posted the example here I was thinking it should not fail. I'll fix this up.
There was a problem hiding this comment.
ah ok, sorry it was not clear
There was a problem hiding this comment.
no worries, I think it was just my limited understanding of things.
|
@elasticmachine test this please |
|
@elasticmachine test this please |
|
@jimczi done |
|
@elasticmachine test this please |
|
@jimczi |
|
hi @dvehar that last test that was failing is now addressed. could you merge master in so we can re-run tests and hopefully have a green build? ;) |
|
@javanna done |
|
@elasticmachine test this please |
|
retest this please |
|
retest this please |
|
retest this please |
This change throws an error if two inner_hits have the same name Closes elastic#37584
* master: Replace awaitBusy with assertBusy in atLeastDocsIndexed (elastic#38190) Adjust SearchRequest version checks (elastic#38181) AwaitsFix testClientSucceedsWithVerificationDisabled (elastic#38213) Zen2ify RareClusterStateIT (elastic#38184) ML: Fix error race condition on stop _all datafeeds and close _all jobs (elastic#38113) AwaitsFix PUT mapping with _doc on an index that has types (elastic#38204) Allow built-in monitoring_user role to call GET _xpack API (elastic#38060) Update geo_shape docs to include unsupported features (elastic#38138) [ML] Remove "8" prefixes from file structure finder timestamp formats (elastic#38016) Disable bwc tests while backporting elastic#38104 (elastic#38182) Enable TLSv1.3 by default for JDKs with support (elastic#38103) Fix _host based require filters (elastic#38173) RestoreService should update primary terms when restoring shards of existing indices (elastic#38177) Throw if two inner_hits have the same name (elastic#37645)
|
@jimczi Thanks for helping me get it through! |
…round-sync-6.x * elastic/6.x: Fix testRestoreIncreasesPrimaryTerms on 6.x (elastic#38314) SQL: Remove exceptions from Analyzer (elastic#38260) (elastic#38287) SQL: Move metrics tracking inside PlanExecutor (elastic#38259) (elastic#38288) Backport of elastic#38311: Move TokenService to seqno powered cas Handle scheduler exceptions (elastic#38183) Mute MlMigrationFullClusterRestartIT#testMigration (elastic#38316) 6.x Backport of elastic#38278: Move ML Optimistic Concurrency Control to Seq No Cleanup construction of interceptors (elastic#38296) Throw if two inner_hits have the same name (elastic#37645) (elastic#38194) AsyncTwoPhaseIndexerTests race condition fixed elastic#38195 Backport#37830 Enable SSL in reindex with security QA tests (elastic#38293) Ensure ILM policies run safely on leader indices (elastic#38140) Introduce ssl settings to reindex from remote (elastic#38292) Fix ordering problem in add or renew lease test (elastic#38281) Mute ReplicationTrackerRetentionLeaseTests#testAddOrRenewRetentionLease (elastic#38276) Fix NPE in Logfile Audit Filter (elastic#38120) (elastic#38271) Enable trace log in FollowerFailOverIT (elastic#38148) SQL: Generate relevant error message when grouping functions are not used in GROUP BY (elastic#38017)
Fixes #37584