Bool query VS filtered query with query filter

Hi list,

In a previous post, I got the following answer to my question:

{
"query" : {
"bool" : {
"should" : [
{
"bool" : {
"must" : [
{ "field" : { "name" : "do*" }},
{ "match" : { "type" : "mammal"}}
]
}
},
{
"bool" : {
"must" : [
{ "field" : { "name" : "le*" }},
{ "match" : { "type" : "reptile"}}
]
}
}
]
}
}
}

Taking a look at the docs, I see this query could also be expressed as
(using query filter):

{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"or": [
{
"and": [
{
"query": {
"field": {
"name": "do*"
}
}
},
{
"term": {
"type": "mammal"
}
}
]
},
{
"and": [
{
"query": {
"match": {
"name": "*le"
}
}
},
{
"term": {
"type": "reptile"
}
}
]
}
]
}
}
}
}

So which would be the optimal one?

Thanks.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

The filtered approach should be faster, especially if the filters are
cached. However, filters do not contribute to the scoring, so if ranking is
important, then queries are the way to go.

--
Ivan

On Thu, Mar 28, 2013 at 7:54 AM, Enrique Medina Montenegro <
e.medina.m@gmail.com> wrote:

Hi list,

In a previous post, I got the following answer to my question:

{
"query" : {
"bool" : {
"should" : [
{
"bool" : {
"must" : [
{ "field" : { "name" : "do*" }},
{ "match" : { "type" : "mammal"}}
]
}
},
{
"bool" : {
"must" : [
{ "field" : { "name" : "le*" }},
{ "match" : { "type" : "reptile"}}
]
}
}
]
}
}
}

Taking a look at the docs, I see this query could also be expressed as
(using query filter):

{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"or": [
{
"and": [
{
"query": {
"field": {
"name": "do*"
}
}
},
{
"term": {
"type": "mammal"
}
}
]
},
{
"and": [
{
"query": {
"match": {
"name": "*le"
}
}
},
{
"term": {
"type": "reptile"
}
}
]
}
]
}
}
}
}

So which would be the optimal one?

Thanks.

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.