# Facet\_filter with multiple ranges

**URL:** <https://discuss.elastic.co/t/facet-filter-with-multiple-ranges/10586>\
**Category:** Elasticsearch\
**Created:** [February 1, 2013, 12:03pm UTC](https://discuss.elastic.co/t/facet-filter-with-multiple-ranges/10586 "2013-02-01T12:03:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sven\_Reissmann](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sven_reissmann/32/2506_2.png) [@Sven\_Reissmann](https://discuss.elastic.co/u/Sven_Reissmann)\
**Post date:** [February 1, 2013, 12:03pm UTC](https://discuss.elastic.co/t/facet-filter-with-multiple-ranges/10586/1 "2013-02-01T12:03:45Z")

</div>

Hi,

I am trying to build a facet filter, that filters on ranges of different  
fields.  
At the bottom there is a short example of what I am trying to do. Of  
course, it does not work because the range-keyword appears twice ...

Any hint on how to do this correctly?

Thanks, Sven.

```
          'facet_filter': {
            'and': [
              {
                'range': {
                  'severity': {
                    'from': 0,
                    'to': 2
                  }
                },
                'range': {
                  'time': {
                    'from': from,
                    'to': now
                  }
                }
              }
            ]
          }

```

--  
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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [February 1, 2013, 12:48pm UTC](https://discuss.elastic.co/t/facet-filter-with-multiple-ranges/10586/2 "2013-02-01T12:48:38Z")

</div>

On Fri, 2013-02-01 at 04:03 -0800, Sven Reissmann wrote:

> Hi,
> 
> I am trying to build a facet filter, that filters on ranges of  
> different fields.  
> At the bottom there is a short example of what I am trying to do. Of  
> course, it does not work because the range-keyword appears twice ...

You're nesting incorrectly. Instead of:

```
and: [
  { range: {...}, range:{...}}
]

```

do:

```
and: [
  { range: {...}},
  { range: {...}}
]

```

clint

> Any hint on how to do this correctly?
> 
> Thanks, Sven.
> 
> ```
> 'facet_filter': {
> 'and': [
> {
> 'range': {
> 'severity': {
> 'from': 0,
> 'to': 2
> }
> },
> 'range': {
> 'time': {
> 'from': from,
> 'to': now
> }
> }
> }
> ]
> }
> 
> ```
> 
> --  
> 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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Sven\_Reissmann](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sven_reissmann/32/2506_2.png) [@Sven\_Reissmann](https://discuss.elastic.co/u/Sven_Reissmann)\
**Post date:** [February 1, 2013, 12:56pm UTC](https://discuss.elastic.co/t/facet-filter-with-multiple-ranges/10586/3 "2013-02-01T12:56:57Z")

</div>

Oha. It's that easy 🙂  
Thank you very much Clinton.

On Friday, February 1, 2013 1:48:38 PM UTC+1, Clinton Gormley wrote:

> On Fri, 2013-02-01 at 04:03 -0800, Sven Reissmann wrote:
> 
> > Hi,
> > 
> > I am trying to build a facet filter, that filters on ranges of  
> > different fields.  
> > At the bottom there is a short example of what I am trying to do. Of  
> > course, it does not work because the range-keyword appears twice ...
> 
> You're nesting incorrectly. Instead of:
> 
> ```
> and: [ 
> { range: {...}, range:{...}} 
> ] 
> 
> ```
> 
> do:
> 
> ```
> and: [ 
> { range: {...}}, 
> { range: {...}} 
> ] 
> 
> ```
> 
> clint
> 
> > Any hint on how to do this correctly?
> > 
> > Thanks, Sven.
> > 
> > ```
> > 'facet_filter': { 
> > 'and': [ 
> > { 
> > 'range': { 
> > 'severity': { 
> > 'from': 0, 
> > 'to': 2 
> > } 
> > }, 
> > 'range': { 
> > 'time': { 
> > 'from': from, 
> > 'to': now 
> > } 
> > } 
> > } 
> > ] 
> > } 
> > 
> > ```
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > For more options, visit [https://groups.google.com/groups/opt\_out](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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![dashed](https://avatars.discourse-cdn.com/v4/letter/d/7cd45c/32.png) [@dashed](https://discuss.elastic.co/u/dashed)\
**Post date:** [June 5, 2014, 3:53pm UTC](https://discuss.elastic.co/t/facet-filter-with-multiple-ranges/10586/4 "2014-06-05T15:53:47Z")

</div>

Hey,

I have the ~same problem, that's my code i don't know where is my error ...

{ 'query': {'match\_all': {}},

'facets': {  
'visite': {  
'terms': {'field': 'is\_newuser', 'size': '21'},  
'facet\_filter': {  
'and': [  
{'range': {'time': {'from' : 1396303200 ,'to' : 1398895200 }}},  
{'range': {'time': {'from' : 1398895201 ,'to' : 1401573600 }}}  
]  
}

```
			  }
  }

```

}

Thx for reading me

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 1:24am UTC](https://discuss.elastic.co/t/facet-filter-with-multiple-ranges/10586/5 "2017-07-06T01:24:26Z")

</div>


