Multiple range filters

Hi,

I am trying to get a query similar to the one below working. The
ranges may not necessarily be consecutive so I need to be able to
retrieve all of the documents that satisify this requirement. Also,
potentially I will need to add other filters so this should work with
the "AND" filter or something equivalent.

{
"query": {"match_all":{} },
"filter" : {
"range" : {
"file_size" : [
{ "from" : 100, "to" : 10000 },
{ "from" : 1000001, "to" : 10000000 } ]
}
}
}

What I have tried is below:

  1. bool filter with two must clauses with the range to search

{
"query": {"match_all":{} },
"filter" : {
"bool" : {
"must" : {"range" : {
"file_size" :
{ "from" : 10, "to" : 10000 }}},
"must" : {"range" : {
"file_size" :
{ "from" : 10001, "to" : 1000000 }
}}}
}
}

  1. two separate "AND" queries in a single "FILTER"

{
"query": {"match_all":{} },
"filter" : {
"and" : [{"range" : {
"file_size" :
{ "from" : 10, "to" : 10000 }}}],
"and" : [{"range" : {
"file_size" :
{ "from" : 10001, "to" : 1000000 }}}]
}
}


  1. Combo "AND" and "OR" in a single filter element

{
"query": {"match_all":{} },
"filter" : {
"and" : [{"term" :
{"file_stages_filetype_result_extension":"htm"}}],
"or" : [{"range" : {
"file_size" :
{ "from" : 10, "to" : 10000 }}},
{"range" : {
"file_size" :
{ "from" : 10001, "to" : 1000000 }}}]
}

}


  1. Combo "AND" and "OR" with two different filters, the result seems
    to OR both filters

{
"query": {"match_all":{} },
"filter" : {
"or" : [{"range" : {
"file_size" :
{ "from" : 10, "to" : 10000 }}},
{"range" : {
"file_size" :
{ "from" : 120001, "to" : 1000000 }}}]
} ,
"filter" : {
"and" : [{"term" :
{"file_stages_filetype_result_extension":"htm"}}]
}
}


  1. Single "AND" query with multiple "RANGE" queries on the same field

{
"query": {"match_all":{} },
"filter" : {
"and" : [{"range" : {
"file_size" :
{ "from" : 10, "to" : 10000 }}},
{"range" : {
"file_size" :
{ "from" : 10001, "to" : 1000000 }}}
],
}
}

Nothing seems to work for what I want it to do. Is there a workaround
I can do to get the results I expect?

Vinny

Try this: gist:995045 · GitHub.

On Friday, May 27, 2011 at 12:28 AM, vinny wrote:

Hi,

I am trying to get a query similar to the one below working. The
ranges may not necessarily be consecutive so I need to be able to
retrieve all of the documents that satisify this requirement. Also,
potentially I will need to add other filters so this should work with
the "AND" filter or something equivalent.

{
"query": {"match_all":{} },
"filter" : {
"range" : {
"file_size" : [
{ "from" : 100, "to" : 10000 },
{ "from" : 1000001, "to" : 10000000 } ]
}
}
}

What I have tried is below:

  1. bool filter with two must clauses with the range to search

{
"query": {"match_all":{} },
"filter" : {
"bool" : {
"must" : {"range" : {
"file_size" :
{ "from" : 10, "to" : 10000 }}},
"must" : {"range" : {
"file_size" :
{ "from" : 10001, "to" : 1000000 }
}}}
}
}

  1. two separate "AND" queries in a single "FILTER"

{
"query": {"match_all":{} },
"filter" : {
"and" : [{"range" : {
"file_size" :
{ "from" : 10, "to" : 10000 }}}],
"and" : [{"range" : {
"file_size" :
{ "from" : 10001, "to" : 1000000 }}}]
}
}


  1. Combo "AND" and "OR" in a single filter element

{
"query": {"match_all":{} },
"filter" : {
"and" : [{"term" :
{"file_stages_filetype_result_extension":"htm"}}],
"or" : [{"range" : {
"file_size" :
{ "from" : 10, "to" : 10000 }}},
{"range" : {
"file_size" :
{ "from" : 10001, "to" : 1000000 }}}]
}

}


  1. Combo "AND" and "OR" with two different filters, the result seems
    to OR both filters

{
"query": {"match_all":{} },
"filter" : {
"or" : [{"range" : {
"file_size" :
{ "from" : 10, "to" : 10000 }}},
{"range" : {
"file_size" :
{ "from" : 120001, "to" : 1000000 }}}]
} ,
"filter" : {
"and" : [{"term" :
{"file_stages_filetype_result_extension":"htm"}}]
}
}


  1. Single "AND" query with multiple "RANGE" queries on the same field

{
"query": {"match_all":{} },
"filter" : {
"and" : [{"range" : {
"file_size" :
{ "from" : 10, "to" : 10000 }}},
{"range" : {
"file_size" :
{ "from" : 10001, "to" : 1000000 }}}
],
}
}

Nothing seems to work for what I want it to do. Is there a workaround
I can do to get the results I expect?

Vinny

Hi Shay,

I tried the gist and it doesn't work, here is the output:
{"took":3,"timed_out":false,"_shards":{"total":5,"successful":
5,"failed":0},"hits":{"total":0,"max_score":null,"hits":}}

As a sanity check I removed one of the range filters and it returns
the correct result. It just doesn't want to work when I give it
multiple ranges to filter by.

thanks for looking into this!

Vinny

On May 27, 7:07 am, Shay Banon shay.ba...@elasticsearch.com wrote:

Try this:gist:995045 · GitHub.

On Friday, May 27, 2011 at 12:28 AM, vinny wrote:

Hi,

I am trying to get a query similar to the one below working. The
ranges may not necessarily be consecutive so I need to be able to
retrieve all of the documents that satisify this requirement. Also,
potentially I will need to add other filters so this should work with
the "AND" filter or something equivalent.

{
"query": {"match_all":{} },
"filter" : {
"range" : {
"file_size" : [
{ "from" : 100, "to" : 10000 },
{ "from" : 1000001, "to" : 10000000 } ]
}
}
}

What I have tried is below:

  1. bool filter with two must clauses with the range to search

{
"query": {"match_all":{} },
"filter" : {
"bool" : {
"must" : {"range" : {
"file_size" :
{ "from" : 10, "to" : 10000 }}},
"must" : {"range" : {
"file_size" :
{ "from" : 10001, "to" : 1000000 }
}}}
}
}

  1. two separate "AND" queries in a single "FILTER"

{
"query": {"match_all":{} },
"filter" : {
"and" : [{"range" : {
"file_size" :
{ "from" : 10, "to" : 10000 }}}],
"and" : [{"range" : {
"file_size" :
{ "from" : 10001, "to" : 1000000 }}}]
}
}


  1. Combo "AND" and "OR" in a single filter element

{
"query": {"match_all":{} },
"filter" : {
"and" : [{"term" :
{"file_stages_filetype_result_extension":"htm"}}],
"or" : [{"range" : {
"file_size" :
{ "from" : 10, "to" : 10000 }}},
{"range" : {
"file_size" :
{ "from" : 10001, "to" : 1000000 }}}]
}

}


  1. Combo "AND" and "OR" with two different filters, the result seems
    to OR both filters

{
"query": {"match_all":{} },
"filter" : {
"or" : [{"range" : {
"file_size" :
{ "from" : 10, "to" : 10000 }}},
{"range" : {
"file_size" :
{ "from" : 120001, "to" : 1000000 }}}]
} ,
"filter" : {
"and" : [{"term" :
{"file_stages_filetype_result_extension":"htm"}}]
}
}


  1. Single "AND" query with multiple "RANGE" queries on the same field

{
"query": {"match_all":{} },
"filter" : {
"and" : [{"range" : {
"file_size" :
{ "from" : 10, "to" : 10000 }}},
{"range" : {
"file_size" :
{ "from" : 10001, "to" : 1000000 }}}
],
}
}

Nothing seems to work for what I want it to do. Is there a workaround
I can do to get the results I expect?

Vinny

Isn't the filter saying "keep documents that have file_size between 10 to
10000 and file_size between 10001 to 100001" which, unless a file has two
different sizes will never happen?

What is it you are trying to achieve? It's not clear to me why you need to
filter on different ranges.

Philippe

On Fri, May 27, 2011 at 16:44, vinny agnellvj@gmail.com wrote:

Hi Shay,

I tried the gist and it doesn't work, here is the output:
{"took":3,"timed_out":false,"_shards":{"total":5,"successful":
5,"failed":0},"hits":{"total":0,"max_score":null,"hits":}}

As a sanity check I removed one of the range filters and it returns
the correct result. It just doesn't want to work when I give it
multiple ranges to filter by.

thanks for looking into this!

Vinny

On May 27, 7:07 am, Shay Banon shay.ba...@elasticsearch.com wrote:

Try this:gist:995045 · GitHub.

On Friday, May 27, 2011 at 12:28 AM, vinny wrote:

Hi,

I am trying to get a query similar to the one below working. The
ranges may not necessarily be consecutive so I need to be able to
retrieve all of the documents that satisify this requirement. Also,
potentially I will need to add other filters so this should work with
the "AND" filter or something equivalent.

{
"query": {"match_all":{} },
"filter" : {
"range" : {
"file_size" : [
{ "from" : 100, "to" : 10000 },
{ "from" : 1000001, "to" : 10000000 } ]
}
}
}

What I have tried is below:

  1. bool filter with two must clauses with the range to search

{
"query": {"match_all":{} },
"filter" : {
"bool" : {
"must" : {"range" : {
"file_size" :
{ "from" : 10, "to" : 10000 }}},
"must" : {"range" : {
"file_size" :
{ "from" : 10001, "to" : 1000000 }
}}}
}
}

  1. two separate "AND" queries in a single "FILTER"

{
"query": {"match_all":{} },
"filter" : {
"and" : [{"range" : {
"file_size" :
{ "from" : 10, "to" : 10000 }}}],
"and" : [{"range" : {
"file_size" :
{ "from" : 10001, "to" : 1000000 }}}]
}
}


  1. Combo "AND" and "OR" in a single filter element

{
"query": {"match_all":{} },
"filter" : {
"and" : [{"term" :
{"file_stages_filetype_result_extension":"htm"}}],
"or" : [{"range" : {
"file_size" :
{ "from" : 10, "to" : 10000 }}},
{"range" : {
"file_size" :
{ "from" : 10001, "to" : 1000000 }}}]
}

}


  1. Combo "AND" and "OR" with two different filters, the result seems
    to OR both filters

{
"query": {"match_all":{} },
"filter" : {
"or" : [{"range" : {
"file_size" :
{ "from" : 10, "to" : 10000 }}},
{"range" : {
"file_size" :
{ "from" : 120001, "to" : 1000000 }}}]
} ,
"filter" : {
"and" : [{"term" :
{"file_stages_filetype_result_extension":"htm"}}]
}
}


  1. Single "AND" query with multiple "RANGE" queries on the same field

{
"query": {"match_all":{} },
"filter" : {
"and" : [{"range" : {
"file_size" :
{ "from" : 10, "to" : 10000 }}},
{"range" : {
"file_size" :
{ "from" : 10001, "to" : 1000000 }}}
],
}
}

Nothing seems to work for what I want it to do. Is there a workaround
I can do to get the results I expect?

Vinny

I can create the facet for the ranges with no problem. What I want to
be able to do is if I select more than one facet I want to be able to
filter on it which doesn't seem to work properly. This what you would
do for pivoting on a data point. It doesn't necessarily have to be
file size, it could be monetary amounts like 1 to 50 dollars and 50.01
to 100.00 dollars. I want to be able to select the facets so that I
filter on those two or more terms / ranges. This is how you would do
a pivot for a facet.

On May 27, 7:44 pm, Philippe Laflamme philippe.lafla...@obiba.org
wrote:

Isn't the filter saying "keep documents that have file_size between 10 to
10000 and file_size between 10001 to 100001" which, unless a file has two
different sizes will never happen?

What is it you are trying to achieve? It's not clear to me why you need to
filter on different ranges.

Philippe

Hi, so it's more a OR filter than a AND ?

On Sat, May 28, 2011 at 6:36 AM, vinny agnellvj@gmail.com wrote:

I can create the facet for the ranges with no problem. What I want to
be able to do is if I select more than one facet I want to be able to
filter on it which doesn't seem to work properly. This what you would
do for pivoting on a data point. It doesn't necessarily have to be
file size, it could be monetary amounts like 1 to 50 dollars and 50.01
to 100.00 dollars. I want to be able to select the facets so that I
filter on those two or more terms / ranges. This is how you would do
a pivot for a facet.

On May 27, 7:44 pm, Philippe Laflamme philippe.lafla...@obiba.org
wrote:

Isn't the filter saying "keep documents that have file_size between 10 to
10000 and file_size between 10001 to 100001" which, unless a file has two
different sizes will never happen?

What is it you are trying to achieve? It's not clear to me why you need to
filter on different ranges.

Philippe

I would think that you need to combine filters of the same facet using an OR
and filters of different facets with an AND.

(file_size: [10, 1000[ OR file_size: [10000, 100000[) AND (price: [0, 50[ OR
price [50, 100[)

etc.

Here's the modified gist:

You "should" get results with this one...

Philippe

On Sat, May 28, 2011 at 00:36, vinny agnellvj@gmail.com wrote:

I can create the facet for the ranges with no problem. What I want to
be able to do is if I select more than one facet I want to be able to
filter on it which doesn't seem to work properly. This what you would
do for pivoting on a data point. It doesn't necessarily have to be
file size, it could be monetary amounts like 1 to 50 dollars and 50.01
to 100.00 dollars. I want to be able to select the facets so that I
filter on those two or more terms / ranges. This is how you would do
a pivot for a facet.

On May 27, 7:44 pm, Philippe Laflamme philippe.lafla...@obiba.org
wrote:

Isn't the filter saying "keep documents that have file_size between 10 to
10000 and file_size between 10001 to 100001" which, unless a file has two
different sizes will never happen?

What is it you are trying to achieve? It's not clear to me why you need
to
filter on different ranges.

Philippe

  • deleted -