syahra712 opened a new pull request, #155:
URL: https://github.com/apache/solr-orbit/pull/155
`convert-workload` translates OpenSearch search bodies with
`translate_to_solr_json_dsl`. When a `bool` is nested inside another `bool`, it
loses its scope in two ways.
**1. Nested filters are hoisted to `fq` from anywhere.** `fq_list` is passed
down into `must_not` and `should` clauses, so a `filter` deep inside them
becomes a top-level, required `fq`:
```python
translate_to_solr_json_dsl({"query": {"bool": {"must_not": [{"bool":
{"filter": [{"term": {"status": "deleted"}}]}}]}}})
# {'query': '*:*', 'filter': ['status:deleted']} <- returns only the
excluded documents
translate_to_solr_json_dsl({"query": {"bool": {"should": [
{"bool": {"filter": [{"term": {"color": "red"}}]}},
{"bool": {"filter": [{"term": {"color": "blue"}}]}}]}}})
# {'query': '*:*', 'filter': ['color:red', 'color:blue']} <- red AND blue
instead of red OR blue
```
**2. A nested bool under `should` is not grouped.** Its clauses are joined
straight into the should group, so its `+` clauses become required for the
whole query:
```python
translate_to_solr_json_dsl({"query": {"bool": {"should": [
{"bool": {"must": [{"term": {"a": 1}}, {"term": {"b": 2}}]}},
{"term": {"c": 3}}]}}})
# {'query': '(+(a:1) +(b:2) c:3)'} <- a AND b, instead of (a AND b) OR c
```
The converted workload then benchmarks a different query, often one that
matches nothing or the wrong documents.
**Fix:** filters are only hoisted to `fq` under `must`, where they are
required anyway. Under `must_not` and `should` they stay inline. A nested bool
under `should` is wrapped in parentheses. The examples above now give
`-(+(status:deleted))`, `((+(color:red)) (+(color:blue)))` and `((+(a:1)
+(b:2)) c:3)`. Hoisting under `must` is unchanged.
Tested: four tests in `test_workload_converter.py`. Three fail on main, and
the fourth checks that hoisting under `must` still works. `ruff check` is clean
and the full unit suite passes (1184 passed, 5 skipped).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]