How to query documents for a field to be null?


(alichi) #1

I am trying to run a query like below:
{"query" : {"term" : { "my_field": null } } }

but it seems that it is not working, it does not return anything (using the
curl command and also the HEAD plugin).

Thanks,
Ali


(David Pilato) #2

See http://www.elasticsearch.org/guide/reference/query-dsl/missing-filter.html

David :wink:
Twitter : @dadoonet / @elasticsearchfr

Le 27 mars 2012 à 03:47, Ali Loghmani loghmani@gmail.com a écrit :

I am trying to run a query like below:
{"query" : {"term" : { "my_field": null } } }

but it seems that it is not working, it does not return anything (using the curl command and also the HEAD plugin).

Thanks,
Ali


(alichi) #3

cool, easy :wink:

On Monday, March 26, 2012 6:47:53 PM UTC-7, Ali Loghmani wrote:

I am trying to run a query like below:
{"query" : {"term" : { "my_field": null } } }

but it seems that it is not working, it does not return anything (using
the curl command and also the HEAD plugin).

Thanks,
Ali


(Shay Banon) #4

Mmm, wondering if we can do that automatically and translate term query /
filter against null to missing one where applicable. Can you open an issue?

On Tue, Mar 27, 2012 at 9:58 PM, Ali Loghmani loghmani@gmail.com wrote:

cool, easy :wink:

On Monday, March 26, 2012 6:47:53 PM UTC-7, Ali Loghmani wrote:

I am trying to run a query like below:
{"query" : {"term" : { "my_field": null } } }

but it seems that it is not working, it does not return anything (using
the curl command and also the HEAD plugin).

Thanks,
Ali


(Anurag Biyani) #5

Aren't {"x": "blah", "y": null}, AND, {"x": "blah"} two different
JSON obejcts ? Shouldn't a json document with a field having value
null should be treated differently then a json document which is
missing the field all together ?
It seems that elasticsearch's "missing" filter treats json value
"null" as equivalent to absence of field. Is this the desired
behavior ?

On Mar 28, 3:31 am, Shay Banon kim...@gmail.com wrote:

Mmm, wondering if we can do that automatically and translate term query /
filter against null to missing one where applicable. Can you open an issue?

On Tue, Mar 27, 2012 at 9:58 PM, Ali Loghmani loghm...@gmail.com wrote:

cool, easy :wink:

On Monday, March 26, 2012 6:47:53 PM UTC-7, Ali Loghmani wrote:

I am trying to run a query like below:
{"query" : {"term" : { "my_field": null } } }

but it seems that it is not working, it does not return anything (using
the curl command and also the HEAD plugin).

Thanks,
Ali


(Clinton Gormley) #6

On Thu, 2012-04-12 at 18:36 -0700, Anurag Biyani wrote:

Aren't {"x": "blah", "y": null}, AND, {"x": "blah"} two different
JSON obejcts ? Shouldn't a json document with a field having value
null should be treated differently then a json document which is
missing the field all together ?
It seems that elasticsearch's "missing" filter treats json value
"null" as equivalent to absence of field. Is this the desired
behavior ?

From a programmer's perspective, yes, they are different. From ES'
perspective, they aren't.

You could work around this by providing a null_value setting in the
mapping which would be indexed when the property is provided but has a
null value.

That, of course, assumes that the value you choose for the null_value
could never occur as a real value for that property

clint

On Mar 28, 3:31 am, Shay Banon kim...@gmail.com wrote:

Mmm, wondering if we can do that automatically and translate term query /
filter against null to missing one where applicable. Can you open an issue?

On Tue, Mar 27, 2012 at 9:58 PM, Ali Loghmani loghm...@gmail.com wrote:

cool, easy :wink:

On Monday, March 26, 2012 6:47:53 PM UTC-7, Ali Loghmani wrote:

I am trying to run a query like below:
{"query" : {"term" : { "my_field": null } } }

but it seems that it is not working, it does not return anything (using
the curl command and also the HEAD plugin).

Thanks,
Ali


(Anurag Biyani) #7

Thanks for the quick reply! :slight_smile:

On Apr 13, 3:30 am, Clinton Gormley cl...@traveljury.com wrote:

On Thu, 2012-04-12 at 18:36 -0700,AnuragBiyaniwrote:

Aren't {"x": "blah", "y": null}, AND, {"x": "blah"} two different
JSON obejcts ? Shouldn't a json document with a field having value
null should be treated differently then a json document which is
missing the field all together ?
It seems that elasticsearch's "missing" filter treats json value
"null" as equivalent to absence of field. Is this the desired
behavior ?

From a programmer's perspective, yes, they are different. From ES'
perspective, they aren't.

You could work around this by providing a null_value setting in the
mapping which would be indexed when the property is provided but has a
null value.

That, of course, assumes that the value you choose for the null_value
could never occur as a real value for that property

clint

On Mar 28, 3:31 am, Shay Banon kim...@gmail.com wrote:

Mmm, wondering if we can do that automatically and translate term query /
filter against null to missing one where applicable. Can you open an issue?

On Tue, Mar 27, 2012 at 9:58 PM, Ali Loghmani loghm...@gmail.com wrote:

cool, easy :wink:

On Monday, March 26, 2012 6:47:53 PM UTC-7, Ali Loghmani wrote:

I am trying to run a query like below:
{"query" : {"term" : { "my_field": null } } }

but it seems that it is not working, it does not return anything (using
the curl command and also the HEAD plugin).

Thanks,
Ali


(system) #8