-
Notifications
You must be signed in to change notification settings - Fork 428
OAK-12353: Group Elasticsearch dynamic boost nested documents by boost score #3079
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
Merged
fabriziofortino
merged 15 commits into
apache:trunk
from
fabriziofortino:issue/OAK-12353
Aug 31, 2026
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
cc5efe7
OAK-12353: Group dynamic boost nested docs by boost score
fabriziofortino e28a7ee
OAK-12353: Enable dynamic boost grouping toggle by default
fabriziofortino 36939dd
OAK-12353: Add end-to-end query tests for dynamic boost grouping
fabriziofortino 54f935a
OAK-12353: simplify logic
fabriziofortino 110ad7f
OAK-12353: Add time-bombed test to prompt toggle removal
fabriziofortino 4225ea9
OAK-12353: (fix) Single boost group unwrapping changes JSON structure…
fabriziofortino 9e365f7
OAK-12353: (fix) 8. toString() does not include dynamicBoostGroups data
fabriziofortino 375b9fa
OAK-12353: Disable norms on dynamic boost value field
fabriziofortino 68511d5
OAK-12353: increase minor internal version for elasticsearch
fabriziofortino 888796c
Merge branch 'trunk' into issue/OAK-12353
fabriziofortino 74abfee
OAK-12353: re-enabled norms, restructure tests
fabriziofortino f29e898
OAK-12353: remove dynamicBoostValueFieldHasNormsDisabled test
fabriziofortino 6abfc7d
OAK-12353: ElasticDynamicBoostTest reset fixture
fabriziofortino 01a49c3
OAK-12353: (minor) remove unused import
fabriziofortino f0fa844
OAK-12353: (minor) remove warnings
fabriziofortino File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
.../test/java/org/apache/jackrabbit/oak/plugins/index/elastic/index/ElasticDocumentTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.jackrabbit.oak.plugins.index.elastic.index; | ||
|
|
||
| import org.junit.After; | ||
| import org.junit.Test; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.util.ArrayList; | ||
| import java.util.Collection; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| public class ElasticDocumentTest { | ||
|
|
||
| @After | ||
| public void resetToggle() { | ||
| ElasticDocument.FT_OAK_12353_ENABLE.set(true); | ||
| } | ||
|
|
||
| @Test | ||
| public void dynamicBoostValuesAreNotGroupedWhenToggleDisabled() { | ||
| ElasticDocument.FT_OAK_12353_ENABLE.set(false); | ||
|
|
||
| ElasticDocument doc = new ElasticDocument("/test"); | ||
| doc.addDynamicBoostField("predictedTagsDynamicBoost", "Replacement Cost", 1.0); | ||
| doc.addDynamicBoostField("predictedTagsDynamicBoost", "Theft", 1.0); | ||
| doc.addDynamicBoostField("predictedTagsDynamicBoost", "GENERAL INSURANCE COMPANY", 0.988); | ||
|
|
||
| Object value = doc.getProperties().get("predictedTagsDynamicBoost"); | ||
| assertTrue(value instanceof Set); | ||
| @SuppressWarnings("unchecked") | ||
| Set<Map<String, Object>> nestedDocs = (Set<Map<String, Object>>) value; | ||
| assertEquals(3, nestedDocs.size()); | ||
| for (Map<String, Object> nestedDoc : nestedDocs) { | ||
| assertTrue(nestedDoc.get(ElasticIndexHelper.DYNAMIC_BOOST_NESTED_VALUE) instanceof String); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void dynamicBoostValuesAreGroupedByBoostByDefault() { | ||
| ElasticDocument doc = new ElasticDocument("/test"); | ||
| doc.addDynamicBoostField("predictedTagsDynamicBoost", "Replacement Cost", 1.0); | ||
| doc.addDynamicBoostField("predictedTagsDynamicBoost", "Theft", 1.0); | ||
| doc.addDynamicBoostField("predictedTagsDynamicBoost", "Alberta", 1.0); | ||
| doc.addDynamicBoostField("predictedTagsDynamicBoost", "GENERAL INSURANCE COMPANY", 0.988); | ||
|
|
||
| Object value = doc.getProperties().get("predictedTagsDynamicBoost"); | ||
| assertTrue(value instanceof Set); | ||
| @SuppressWarnings("unchecked") | ||
| Set<Map<String, Object>> nestedDocs = (Set<Map<String, Object>>) value; | ||
| // one nested doc for the 3 values sharing boost=1.0, one for the distinct boost=0.988 | ||
| assertEquals(2, nestedDocs.size()); | ||
|
|
||
| boolean foundGrouped = false; | ||
| boolean foundSingle = false; | ||
| for (Map<String, Object> nestedDoc : nestedDocs) { | ||
| Object boost = nestedDoc.get(ElasticIndexHelper.DYNAMIC_BOOST_NESTED_BOOST); | ||
| Object nestedValue = nestedDoc.get(ElasticIndexHelper.DYNAMIC_BOOST_NESTED_VALUE); | ||
| if (Double.valueOf(1.0).equals(boost)) { | ||
| assertTrue(nestedValue instanceof Collection); | ||
| @SuppressWarnings("unchecked") | ||
| Collection<String> values = (Collection<String>) nestedValue; | ||
| assertEquals(List.of("Replacement Cost", "Theft", "Alberta"), new ArrayList<>(values)); | ||
| foundGrouped = true; | ||
| } else if (Double.valueOf(0.988).equals(boost)) { | ||
| assertEquals("GENERAL INSURANCE COMPANY", nestedValue); | ||
| foundSingle = true; | ||
| } | ||
| } | ||
| assertTrue(foundGrouped); | ||
| assertTrue(foundSingle); | ||
| } | ||
|
|
||
| @Test | ||
| public void ft_oak_12353_toggleShouldBeRemoved() { | ||
| // Time-bombed: if this test fails, the feature toggle FT_OAK-12353 and its guard in | ||
| // ElasticDocument#addDynamicBoostField/#getProperties should be removed — the grouping | ||
| // has been enabled by default in production long enough. | ||
| assertTrue("Feature toggle " + ElasticDocument.FT_OAK_12353 + " is overdue for removal", | ||
| LocalDate.now().isBefore(LocalDate.of(2027, 8, 12))); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.