Commit 475d8c1
Fix regression: preserve not(not X) in BooleanFlatteningRewriter (opensearch-project#19273)
* Fix regression: preserve not(not X) in BooleanFlatteningRewriter Resolve opensearch-project#19266 by fixing double-negation under MUST_NOT introduced by opensearch-project#19060 When parent is must_not and nested bool has only must_not clauses, rewrite to a positive OR:
not(bool(must_not:[X1..Xn])) => filter(bool(should:[X1..Xn], minimum_should_match=1))
Use FILTER (not MUST) to preserve non-scoring semantics of must_not
Leave other flattenings unchanged; only trigger on pure must_not nested bool
Add unit test: testDoubleNegationConvertedToPositiveMustShould
Signed-off-by: Atri Sharma <atri.jiit@gmail.com>
* spotless output
Signed-off-by: Atri Sharma <atri.jiit@gmail.com>
* Remove must_not rewrite
Signed-off-by: Atri Sharma <atri.jiit@gmail.com>
* Query rewriting tests: expand coverage; enforce idempotence and non-flattening invariants
This change broadens the test suite for query rewriting to codify semantics, guard against regressions, and address maintainer feedback around non‑idempotent must_not handling.
BooleanFlatteningRewriterTests:
Add explicit “don’t flatten” cases when nested bool has non-default boost, has queryName, or nested should has minimum_should_match.
Add idempotence check (second rewrite is a no-op in structure/serialization).
MatchAllRemovalRewriterTests:
Remove match_all from must when a non-scoring context (filter) is present.
Remove deeply nested match_all under filter-in-filter.
MustToFilterRewriterTests:
Move boosted numeric term/range queries to filter; ensure text queries remain scoring.
With null QueryShardContext, move ranges but do not move numeric term/terms.
MustNotToShouldRewriterTests:
Add idempotence check.
Ensure no rewrite for multi-valued numeric fields (complements must_not disabled).
TermsMergingRewriterTests:
Should-clause merging above threshold.
Per-field merging: only coalesce within the same field; mixed fields remain separate.
QueryRewriterRegistryTests:
Dynamic setting update for terms merging threshold (e.g., 16 → 32) changes behavior as expected.
Registry idempotence: applying rewrite twice yields identical structure.
Signed-off-by: Atri Sharma <atri.jiit@gmail.com>
---------
Signed-off-by: Atri Sharma <atri.jiit@gmail.com>1 parent c333319 commit 475d8c1
File tree
7 files changed
+278
-15
lines changed- server/src
- main/java/org/opensearch/search/query/rewriters
- test/java/org/opensearch/search/query
- rewriters
7 files changed
+278
-15
lines changedLines changed: 6 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
133 | | - | |
| 133 | + | |
134 | 134 | | |
135 | 135 | | |
136 | | - | |
137 | 136 | | |
138 | 137 | | |
139 | 138 | | |
| |||
160 | 159 | | |
161 | 160 | | |
162 | 161 | | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
163 | 167 | | |
164 | 168 | | |
165 | 169 | | |
| |||
178 | 182 | | |
179 | 183 | | |
180 | 184 | | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | 185 | | |
187 | 186 | | |
188 | 187 | | |
| |||
Lines changed: 39 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | 14 | | |
16 | 15 | | |
17 | 16 | | |
| |||
93 | 92 | | |
94 | 93 | | |
95 | 94 | | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
96 | 117 | | |
97 | 118 | | |
98 | 119 | | |
99 | 120 | | |
100 | 121 | | |
101 | 122 | | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
102 | 134 | | |
103 | 135 | | |
104 | 136 | | |
| |||
114 | 146 | | |
115 | 147 | | |
116 | 148 | | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
| 149 | + | |
121 | 150 | | |
122 | | - | |
123 | 151 | | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
124 | 155 | | |
125 | 156 | | |
126 | 157 | | |
| |||
147 | 178 | | |
148 | 179 | | |
149 | 180 | | |
150 | | - | |
151 | | - | |
| 181 | + | |
| 182 | + | |
152 | 183 | | |
153 | 184 | | |
154 | 185 | | |
| |||
Lines changed: 116 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
105 | 163 | | |
106 | 164 | | |
107 | 165 | | |
| |||
140 | 198 | | |
141 | 199 | | |
142 | 200 | | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
143 | 248 | | |
144 | 249 | | |
145 | 250 | | |
| |||
179 | 284 | | |
180 | 285 | | |
181 | 286 | | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
182 | 298 | | |
Lines changed: 27 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
100 | 127 | | |
101 | 128 | | |
102 | 129 | | |
| |||
Lines changed: 32 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
137 | 169 | | |
138 | 170 | | |
139 | 171 | | |
| |||
Lines changed: 30 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
202 | 202 | | |
203 | 203 | | |
204 | 204 | | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
205 | 235 | | |
206 | 236 | | |
207 | 237 | | |
| |||
Lines changed: 28 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
59 | 87 | | |
60 | 88 | | |
61 | 89 | | |
| |||
0 commit comments