Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_exists_ doesn't work on objects #5142

Closed
bobrik opened this issue Feb 17, 2014 · 5 comments
Closed

_exists_ doesn't work on objects #5142

bobrik opened this issue Feb 17, 2014 · 5 comments

Comments

@bobrik
Copy link
Contributor

bobrik commented Feb 17, 2014

At least in 1.0.0

# create index and object
curl -X PUT 'http://127.0.0.1:9200/wtf/?pretty'
curl -X PUT 'http://127.0.0.1:9200/wtf/test/1?pretty' -d '{"complex": { "object": "it is" }, "simple": "value"}'

# no results
curl -X POST 'http://127.0.0.1:9200/wtf/test/_search?pretty&q=_exists_:complex'
# has results
curl -X POST 'http://127.0.0.1:9200/wtf/test/_search?pretty&q=_exists_:simple'

# has results
curl -X POST 'http://127.0.0.1:9200/wtf/test/_search?pretty' -d '{ "query": { "filtered": { "filter": { "not": { "missing": { "field": "complex" } } } } } }'

# has results
curl -X POST 'http://127.0.0.1:9200/wtf/test/_search?pretty' -d '{ "query": { "filtered": { "filter": { "not": { "missing": { "field": "simple" } } } } } }'

This behaviour should be either fixed or noted in docs.

@jpountz
Copy link
Contributor

jpountz commented Feb 17, 2014

The exists filter works by looking at matches in the inverted index for any value of the given field. The reason why it doesn't work on object is that they are not indexed. In the example that you gave, the inverted index only has entries for complex.object and simple.

I will a a note to the documentation.

@jpountz jpountz self-assigned this Feb 17, 2014
@bobrik
Copy link
Contributor Author

bobrik commented Feb 17, 2014

So missing filter will use field data and not inverted index, right?

@jpountz
Copy link
Contributor

jpountz commented Feb 17, 2014

The missing filter works exactly as if you wrapped the exists filter under a not filter, so the same limitations apply.

@bobrik
Copy link
Contributor Author

bobrik commented Feb 17, 2014

Since this works:

curl -X POST 'http://127.0.0.1:9200/wtf/test/_search?pretty' -d '{ "query": { "filtered": { "filter": { "exists": { "field": "complex" } } } } }'

and this doesn't:

curl -X POST 'http://127.0.0.1:9200/wtf/test/_search?pretty&q=_exists_:complex'

I understand that _exists_ in query only uses inverted index, but exists filter knows that complex is object and cannot be found in index so field data should be used. Do I get this right?

@jpountz
Copy link
Contributor

jpountz commented Feb 17, 2014

I had to check the code to understand what happens, the difference is that exists tries to be smarter than _exists_ when matching an object by using sub-fields. That is, exists is able to translate "exists": { "field": "complex"} to "exists": { "field": "complex.object"}. Let me see if I can fix _exists_ to behave consistently with exists.

jpountz added a commit to jpountz/elasticsearch that referenced this issue Feb 17, 2014
`_exists_` and `_missing_` miss field name expansion that `exists` and
`missing` have, which allows these filters to work on `object` fields.

Close elastic#5142
@spinscale spinscale added the bug label Feb 20, 2014
jpountz added a commit that referenced this issue Feb 20, 2014
`_exists_` and `_missing_` miss field name expansion that `exists` and
`missing` have, which allows these filters to work on `object` fields.

Close #5142
jpountz added a commit that referenced this issue Feb 20, 2014
`_exists_` and `_missing_` miss field name expansion that `exists` and
`missing` have, which allows these filters to work on `object` fields.

Close #5142
mute pushed a commit to mute/elasticsearch that referenced this issue Jul 29, 2015
`_exists_` and `_missing_` miss field name expansion that `exists` and
`missing` have, which allows these filters to work on `object` fields.

Close elastic#5142
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants