Query string parentheses bug

Query string seems not respecting AND priority against OR.

In a very simple index with 3 documents:

{
_id: "2",
_score: 1,
_source: {
name: "vincent",
age: 20
}
},
{
_id: "1",
_score: 1,
_source: {
name: "tom",
age: 25
}
},
{
_id: "3",
_score: 1,
_source: {
name: "alicia",
age: 2
}
}

Why (tom AND age:25) OR age:2 is not giving same results than tom AND age:25 OR age:2 ?

Hi @ebuildy,

Elasticsearch will turn your queries into Lucene queries internally. Here is what happens:

Elasticsearch: (tom AND age:25) OR age:2
Lucene: (+_all:tom +age: 25) age: 2 

Which means: "All documents that contain "tom" AND are 25 OR the ones that are 2". Both "tom" and "alica" match these criteria.

Whereas

Elasticsearch: tom AND age:25 OR age:2
Lucene: +_all:tom +age: 25 age: 2

means "all document that contain tom AND are 25. If they are 2 as well give them some more score".

As in this case, only "tom" matches.

I hope that helps.

Daniel

True, is not "real" conditional, I forgot that!

Many thanks for the clarification.

I tried also "(name:tom AND age:18) OR age:2" VS "name:tom AND age:18 OR age:2" same thing.

BTW Is not possible to close the conversation in order to mark it as resolved?

Hi @ebuildy,

Glad that I could help you.

I think you need to click the little checkbox below my answer to indicate that this response solves your question. Then it should be marked as resolved.

Daniel