I am using OpenSearch to make query to documents in my database, currently I am doing this search (I'm using default_operator=AND
, and the terms between "" are terms 1 4 and 5 are terms of two words that I'm omitting,i.e: "foo bar"):
"term 1" term2 term3 "term 4" OR "term 5"
but when I look at my result, there are documents that have just "term 1" term2 term3
. This changes if I add parentheses, this search returns what I want:
("term 1" term2 term3 "term 4") OR ("term 5")
Is there any sense to have difference between the results of these queries?
I also tried to change the "term 4" position to:
"term 1" "term 4" term2 term3 OR "term 5"
and the results also are differents from the results of the first query, and for me it doesn't make sense.
This is an example of an almost full query:
{
"query": {
"bool": {
"must": [
{
"bool": {
"should": [
{
"query_string": {
"query": "\"term 1\" term2 term3 \"term 4\" OR \"term 5\"",
"fields": [
"my_field.analyzed"
],
"default_operator": "AND",
"boost": 0.1
}
},
{
"query_string": {
"query": "\"term 1\" term2 term3 \"term 4\" OR \"term 5\"",
"fields": [
"my_field_2",
"my_field_3"
],
"boost": 0.5
}
}
]
}
},
{
"exists": {
"field": "my_field"
}
}
],