Can anyone please explain why I got all different results in the following query_string queries (all are the same except the parentheses)
-
A OR B AND C
-
(A OR B) AND C
-
A OR (B AND C)
The index only has the three documents in total details as below, #1 and #3 are expected to have the same result, but all the three are different.
but actual result:
#1 returns only 1 doc
#2 returns 2 docs
#3 returns all the 3 docs
Here is the test case
{
"took": 5,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 3,
"max_score": 0.5753642,
"hits": [
{
"_index": "testquery",
"_type": "_doc",
"_id": "00IB737J1OF7D8RB4TUJ42LAES0082HF",
"_score": 0.5753642,
"_source": {
"A": "3100007",
"B": "Routed"
}
},
{
"_index": "testquery",
"_type": "_doc",
"_id": "00MJOP7K6OF7D1SA51UJ42LAES005PIJ",
"_score": 0.2876821,
"_source": {
"A": "3100000",
"B": "Terminated"
}
},
{
"_index": "testquery",
"_type": "_doc",
"_id": "00THNBNJVCF7D2PI51MJ42LAES005LV1",
"_score": 0.2876821,
"_source": {
"A": "3100000",
"B": "Routed"
}
}
]
}
}
For A OR B AND C
Query:
POST testquery/_search
{
"query": {
"query_string": {
"query": "A.keyword:3100000 OR A.keyword:3100007 AND B.keyword:Routed"
}
}
}
Result:
{
"took": 4,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0.5753642,
"hits": [
{
"_index": "testquery",
"_type": "_doc",
"_id": "00IB737J1OF7D8RB4TUJ42LAES0082HF",
"_score": 0.5753642,
"_source": {
"A": "3100007",
"B": "Routed"
}
}
]
}
}
For (A OR B) AND C
Query
POST testquery/_search
{
"query": {
"query_string": {
"query": "(A.keyword:3100000 OR A.keyword:3100007) AND B.keyword:Routed"
}
}
}
Results
{
"took": 6,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 0.5753642,
"hits": [
{
"_index": "testquery",
"_type": "_doc",
"_id": "00IB737J1OF7D8RB4TUJ42LAES0082HF",
"_score": 0.5753642,
"_source": {
"A": "3100007",
"B": "Routed"
}
},
{
"_index": "testquery",
"_type": "_doc",
"_id": "00THNBNJVCF7D2PI51MJ42LAES005LV1",
"_score": 0.5753642,
"_source": {
"A": "3100000",
"B": "Routed"
}
}
]
}
}
For A OR (B AND C)
Query
POST testquery/_search
{
"query": {
"query_string": {
"query": "A.keyword:3100000 OR (A.keyword:3100007 AND B.keyword:Routed)"
}
}
}
Results
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 3,
"max_score": 0.5753642,
"hits": [
{
"_index": "testquery",
"_type": "_doc",
"_id": "00IB737J1OF7D8RB4TUJ42LAES0082HF",
"_score": 0.5753642,
"_source": {
"A": "3100007",
"B": "Routed"
}
},
{
"_index": "testquery",
"_type": "_doc",
"_id": "00MJOP7K6OF7D1SA51UJ42LAES005PIJ",
"_score": 0.2876821,
"_source": {
"A": "3100000",
"B": "Terminated"
}
},
{
"_index": "testquery",
"_type": "_doc",
"_id": "00THNBNJVCF7D2PI51MJ42LAES005LV1",
"_score": 0.2876821,
"_source": {
"A": "3100000",
"B": "Routed"
}
}
]
}
}