# Using missing filter into query, right syntax?

**URL:** <https://discuss.elastic.co/t/using-missing-filter-into-query-right-syntax/9288>\
**Category:** Elasticsearch\
**Created:** [October 9, 2012, 11:34am UTC](https://discuss.elastic.co/t/using-missing-filter-into-query-right-syntax/9288 "2012-10-09T11:34:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pere\_roca\_ristol](https://avatars.discourse-cdn.com/v4/letter/p/d26b3c/32.png) [@pere\_roca\_ristol](https://discuss.elastic.co/u/pere_roca_ristol)\
**Post date:** [October 9, 2012, 11:34am UTC](https://discuss.elastic.co/t/using-missing-filter-into-query-right-syntax/9288/1 "2012-10-09T11:34:08Z")

</div>

it's the first time I use the 'missing' parameter and I am not sure if I am  
doing something wrong as i am not getting what i expect.

Can someone tell me if the missing condition is correctly integrated in  
this query? it should created 5 facets, counting for each one only the  
occurrences for which decimallatitude field is 'not set in the index' or  
its value is null.

```
curl -XGET 

```

http://my\_url:9200/idx\_occurrence/Occurrene/\_search?pretty=true -d '{  
"filter":{"missing":{"field":"decimallatitude","existence" :  
true,"null\_value" : true}},"query": { "query\_string" :{ "fields" :  
["dataset"], "query": "3", "default\_operator" : "AND" } }, "facets": {  
"test": { "terms": { "field" :["kingdom\_interpreted"],"size" : 5 } } } }'

thanks in advance,

Pere

--

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 9, 2012, 11:46am UTC](https://discuss.elastic.co/t/using-missing-filter-into-query-right-syntax/9288/2 "2012-10-09T11:46:45Z")

</div>

One thing you have to know is that filter are not applied to facets.

So, if you want to reduce your terms in facet with a filter, you have to ask for  
it: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/facets/index.html)  
[http://www.elasticsearch.org/guide/reference/api/search/facets/index.html](http://www.elasticsearch.org/guide/reference/api/search/facets/index.html)

Facet Filter

All facets can be configured with an additional filter (explained in the Query  
DSL [http://www.elasticsearch.org/guide/reference/query-dsl](http://www.elasticsearch.org/guide/reference/query-dsl) section), which  
will reduce the documents they use for computing results. An example with a term  
filter:

{  
"facets" : {  
"" : {  
"" : {  
...  
},  
"facet\_filter" : {  
"term" : { "user" : "kimchy"}  
}  
}  
}  
}

Note that this is different from a facet of the filter  
[http://www.elasticsearch.org/guide/reference/api/search/facets/filter-facet.html](http://www.elasticsearch.org/guide/reference/api/search/facets/filter-facet.html)  
type.

Does it help ?

David.

Le 9 octobre 2012 à 13:34, pere roca ristol [peroc79@gmail.com](mailto:peroc79@gmail.com) a écrit :

> it's the first time I use the 'missing' parameter and I am not sure if I am  
> doing something wrong as i am not getting what i expect.
> 
> Can someone tell me if the missing condition is correctly integrated in this  
> query? it should created 5 facets, counting for each one only the occurrences  
> for which decimallatitude field is 'not set in the index' or its value is  
> null.
> 
> ```
> curl -XGET
> 
> ```
> 
> http://my\_url:9200/idx\_occurrence/Occurrene/\_search?pretty=true -d '{  
> "filter":{"missing":{"field":"decimallatitude","existence" :  
> true,"null\_value" : true}},"query": { "query\_string" :{ "fields" :  
> ["dataset"], "query": "3", "default\_operator" : "AND" } }, "facets": { "test":  
> { "terms": { "field" :["kingdom\_interpreted"],"size" : 5 } } } }'
> 
> thanks in advance,
> 
> Pere
> 
> --

--  
David Pilato  
[http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
[http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--

---

<div class="post-metadata">

**Author:** ![pere\_roca\_ristol](https://avatars.discourse-cdn.com/v4/letter/p/d26b3c/32.png) [@pere\_roca\_ristol](https://discuss.elastic.co/u/pere_roca_ristol)\
**Post date:** [October 9, 2012, 12:11pm UTC](https://discuss.elastic.co/t/using-missing-filter-into-query-right-syntax/9288/3 "2012-10-09T12:11:12Z")

</div>

thanks for the info. I am not sure that I can use 'missing' inside a  
facet\_filter, at least for me it´s not working...even if it gives no error  
on console (see new curl below)

I have occurrences that don´t have decimalLatitude field, and i want to  
exlude them from the facet.

curl -XGET http://my\_url:9200/idx\_occurrence/Occurren/\_search?pretty=true-d  
'{ "query": { "query\_string" :{ "fields" : ["dataset"], "query": "3",  
"default\_operator" : "AND" } }, "facets": { "test": { "terms": { "field"  
:["kingdom\_interpreted"],"size" : 5 }, "facet\_filter" :  
{"missing":{"field":"decimalLatitude"}} } } }'

2012/10/9 David Pilato [david@pilato.fr](mailto:david@pilato.fr)

> \*\*  
> One thing you have to know is that filter are not applied to facets.
> 
> So, if you want to reduce your terms in facet with a filter, you have to  
> ask for it:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/facets/index.html)
> 
> Facet Filter
> 
> All facets can be configured with an additional filter (explained in the  
> Query DSL [http://www.elasticsearch.org/guide/reference/query-dsl](http://www.elasticsearch.org/guide/reference/query-dsl) section),  
> which _will_ reduce the documents they use for computing results. An  
> example with a _term_ filter:
> 
> {  
> "facets" : {  
> "" : {  
> "" : {  
> ...  
> },  
> "facet\_filter" : {  
> "term" : { "user" : "kimchy"}  
> }  
> }  
> }  
> }
> 
> Note that this is different from a facet of the filter[http://www.elasticsearch.org/guide/reference/api/search/facets/filter-facet.html](http://www.elasticsearch.org/guide/reference/api/search/facets/filter-facet.html)  
> type.
> 
> Does it help ?
> 
> David.
> 
> Le 9 octobre 2012 à 13:34, pere roca ristol [peroc79@gmail.com](mailto:peroc79@gmail.com) a écrit :
> 
> it's the first time I use the 'missing' parameter and I am not sure if I  
> am doing something wrong as i am not getting what i expect.
> 
> Can someone tell me if the missing condition is correctly integrated in  
> this query? it should created 5 facets, counting for each one only the  
> occurrences for which decimallatitude field is 'not set in the index' or  
> its value is null.
> 
> ```
> curl -XGET
> 
> ```
> 
> http://my\_url:9200/idx\_occurrence/Occurrene/\_search?pretty=true -d '{  
> "filter":{"missing":{"field":"decimallatitude","existence" :  
> true,"null\_value" : true}},"query": { "query\_string" :{ "fields" :  
> ["dataset"], "query": "3", "default\_operator" : "AND" } }, "facets": {  
> "test": { "terms": { "field" :["kingdom\_interpreted"],"size" : 5 } } } }'
> 
> thanks in advance,
> 
> Pere
> 
> --
> 
> --  
> David Pilato  
> [http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
> [http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> --

--

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 9, 2012, 12:20pm UTC](https://discuss.elastic.co/t/using-missing-filter-into-query-right-syntax/9288/4 "2012-10-09T12:20:25Z")

</div>

Are you able to get results without asking for facets?  
I mean: "is your query/filter correct and gives you expected results?"

Perhaps, you can provide a full curl recreation?

Le 9 octobre 2012 à 14:11, pere roca ristol [peroc79@gmail.com](mailto:peroc79@gmail.com) a écrit :

> thanks for the info. I am not sure that I can use 'missing' inside a  
> facet\_filter, at least for me it´s not working...even if it gives no error on  
> console (see new curl below)
> 
> I have occurrences that don´t have decimalLatitude field, and i want to  
> exlude them from the facet.
> 
> curl -XGET http://my\_url:9200/idx\_occurrence/Occurren/\_search?pretty=true  
> [http://my\_url:9200/idx\_occurrence/Occurren/\_search?pretty=true](http://my_url:9200/idx_occurrence/Occurren/_search?pretty=true) -d '{  
> "query": { "query\_string" :{ "fields" : ["dataset"], "query": "3",  
> "default\_operator" : "AND" } }, "facets": { "test": { "terms": { "field"  
> :["kingdom\_interpreted"],"size" : 5 }, "facet\_filter" :  
> {"missing":{"field":"decimalLatitude"}} } } }'
> 
> 2012/10/9 David Pilato \<[david@pilato.fr](mailto:david@pilato.fr) [mailto:david@pilato.fr](mailto:david@pilato.fr) \>
> 
> > > One thing you have to know is that filter are not applied to facets.
> > 
> > So, if you want to reduce your terms in facet with a filter, you have to  
> > ask for it:  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/facets/index.html)  
> > [http://www.elasticsearch.org/guide/reference/api/search/facets/index.html](http://www.elasticsearch.org/guide/reference/api/search/facets/index.html)
> > 
> > Facet Filter
> > 
> > All facets can be configured with an additional filter (explained in the  
> > Query DSL [http://www.elasticsearch.org/guide/reference/query-dsl](http://www.elasticsearch.org/guide/reference/query-dsl)  
> > section), which will reduce the documents they use for computing results.  
> > An example with a term filter:
> > 
> > {  
> > "facets" : {  
> > "" : {
> > 
> > ```
> > "<FACET TYPE>" : {
> > ...
> > },
> > 
> > "facet_filter" : {
> > "term" : { "user" : "kimchy"}
> > 
> > }
> > }
> > }
> > 
> > ```
> > 
> > }
> > 
> > Note that this is different from a facet of the filter  
> > [http://www.elasticsearch.org/guide/reference/api/search/facets/filter-facet.html](http://www.elasticsearch.org/guide/reference/api/search/facets/filter-facet.html)  
> > type.
> > 
> > Does it help ?
> > 
> > David.
> > 
> > Le 9 octobre 2012 à 13:34, pere roca ristol \< [peroc79@gmail.com](mailto:peroc79@gmail.com)  
> > [mailto:peroc79@gmail.com](mailto:peroc79@gmail.com) \> a écrit :
> > 
> > ```
> > > > > it's the first time I use the 'missing' parameter and I am not
> > > > > sure if I am doing something wrong as i am not getting what i
> > > > > expect.
> > 
> > ```
> > 
> > > ```
> > > Can someone tell me if the missing condition is correctly integrated
> > > 
> > > ```
> > > 
> > > in this query? it should created 5 facets, counting for each one only the  
> > > occurrences for which decimallatitude field is 'not set in the index' or  
> > > its value is null.
> > > 
> > > ```
> > > curl -XGET
> > > 
> > > ```
> > > 
> > > http://my\_url:9200/idx\_occurrence/Occurrene/\_search?pretty=true  
> > > [http://my\_url:9200/idx\_occurrence/Occurrene/\_search?pretty=true](http://my_url:9200/idx_occurrence/Occurrene/_search?pretty=true) -d '{  
> > > "filter":{"missing":{"field":"decimallatitude","existence" :  
> > > true,"null\_value" : true}},"query": { "query\_string" :{ "fields" :  
> > > ["dataset"], "query": "3", "default\_operator" : "AND" } }, "facets": {  
> > > "test": { "terms": { "field" :["kingdom\_interpreted"],"size" : 5 } } } }'
> > > 
> > > ```
> > > thanks in advance,
> > > 
> > > Pere
> > > 
> > > --
> > > 
> > > ```
> > > 
> > > > >
> > 
> > --  
> > David Pilato  
> > [http://www.scrutmydocs.org/](http://www.scrutmydocs.org/) [http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
> > [http://dev.david.pilato.fr/](http://dev.david.pilato.fr/) [http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
> > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > 
> > --
> > 
> > >
> 
> --

--  
David Pilato  
[http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
[http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--

---

<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, 3:09am UTC](https://discuss.elastic.co/t/using-missing-filter-into-query-right-syntax/9288/5 "2017-07-06T03:09:36Z")

</div>


