Nested queries fails to work in conjunction with plan AND if inside a parenthesis
Nested queries fails to work in conjunction with plan AND if inside a parenthesis. For example, query as below was transformed incorrectly:
"(nested(data.VerticalMeasurements, (VerticalMeasurement:>300 AND VerticalMeasurementUnitOfMeasureID:\"namespace:reference-data--UnitOfMeasure:M:\"))
AND kind:osdu\\:wks\\:master-data--Wellbore\\:1.0.0)"
The expected transformed elastic search query should:
{
"bool": {
"must": [{
"bool": {
"must": [{
"nested": {
"query": {
"query_string": {
"query": "(data.NestedTest.NumberTest:(12345.0 OR 0) AND data.NestedTest.StringTest:\"test string\")",
"fields": [],
"type": "best_fields",
"default_operator": "or",
"max_determinized_states": 10000,
"allow_leading_wildcard": false,
"enable_position_increments": true,
"fuzziness": "AUTO",
"fuzzy_prefix_length": 0,
"fuzzy_max_expansions": 50,
"phrase_slop": 0,
"escape": false,
"auto_generate_synonyms_phrase_query": true,
"fuzzy_transpositions": true,
"boost": 1.0
}
},
"path": "data.NestedTest",
"ignore_unmapped": false,
"score_mode": "avg",
"boost": 1.0
}
}, {
"query_string": {
"query": "data.First:\"Example*\"",
"fields": [],
"type": "best_fields",
"default_operator": "or",
"max_determinized_states": 10000,
"allow_leading_wildcard": false,
"enable_position_increments": true,
"fuzziness": "AUTO",
"fuzzy_prefix_length": 0,
"fuzzy_max_expansions": 50,
"phrase_slop": 0,
"escape": false,
"auto_generate_synonyms_phrase_query": true,
"fuzzy_transpositions": true,
"boost": 1.0
}
}
],
"adjust_pure_negative": true,
"boost": 1.0
}
}
],
"adjust_pure_negative": true,
"boost": 1.0
}
}
But it was transformed to:
{
"bool": {
"must": [{
"nested": {
"query": {
"query_string": {
"query": "(data.VerticalMeasurements.VerticalMeasurement:>300 AND data.VerticalMeasurements.VerticalMeasurementUnitOfMeasureID:\\\"namespace:reference-data--UnitOfMeasure:M:\\\") AND data.VerticalMeasurements.kind:osdu\\\\:wks\\\\:master-data--Wellbore\\\\:1.0.0",
"fields": [],
"type": "best_fields",
"default_operator": "or",
"max_determinized_states": 10000,
"allow_leading_wildcard": false,
"enable_position_increments": true,
"fuzziness": "AUTO",
"fuzzy_prefix_length": 0,
"fuzzy_max_expansions": 50,
"phrase_slop": 0,
"escape": false,
"auto_generate_synonyms_phrase_query": true,
"fuzzy_transpositions": true,
"boost": 1.0
}
},
"path": "data.VerticalMeasurements",
"ignore_unmapped": false,
"score_mode": "avg",
"boost": 1.0
}
}
],
"adjust_pure_negative": true,
"boost": 1.0
}
}
Edited by Zhibin Mai