Skip to content

Conversation

@jtibshirani
Copy link
Contributor

It's possible for a constant_keyword to have a 'null' value before any documents
are seen that contain a value for the field. In this case, no documents have a
value for the field, and 'exists' queries should return no documents.

Fixes #53545.

It's possible for a constant_keyword to have a 'null' value before any documents
are seen that contain a value for the field. In this case, no documents have a
value for the field, and 'exists' queries should return no documents.
@jtibshirani jtibshirani added >bug :Search/Search Search-related issues that do not fall into other categories v8.0.0 v7.8.0 v7.7.1 labels Apr 24, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search (:Search/Search)

Copy link
Member

@cbuescher cbuescher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change in itself looks good to me.

Just a short clarifying question/remark: with this behaviour, the moment the first document is indexed that sets the constant fields value, all previously indexed documents will also show up in an "exists" query for that field. This might be suprising for some users, so maybe a short remark in the docs is in order? I also wonder if the current behaviour (always returning all docs regardless of a set value) isn't less suprising. The act of adding a "constant" field to the mapping by the user might be considered as meaning "this field exists on all documents across the board"? Would that also make sense to you? I'm torn which behaviour I would prefer as a user, maybe someone else should also weigh in on this.

@jtibshirani
Copy link
Contributor Author

jtibshirani commented Apr 30, 2020

Thanks @cbuescher for reviewing! I'd also be happy if others weighed in.

My understanding of exists queries is that they check if a document contains a value for a field. If the value is missing or null, it won't be returned. I think of an exists query as being semantically equivalent to the wildcard query field: * -- and for constant_keyword, wildcard queries will always return no documents if the value is not set.

Copy link
Contributor

@jimczi jimczi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, should we add a small note in the docs to explain this behavior ?

Copy link
Member

@cbuescher cbuescher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jtibshirani thanks for your thought, just wanted to run these thoughts past you.

@jtibshirani jtibshirani merged commit bb04fbc into elastic:master May 4, 2020
@jtibshirani jtibshirani deleted the constant-keyword branch May 4, 2020 16:06
jtibshirani added a commit that referenced this pull request May 4, 2020
…55757)

It's possible for a constant_keyword to have a 'null' value before any documents
are seen that contain a value for the field. In this case, no documents have a
value for the field, and 'exists' queries should return no documents.
jtibshirani added a commit that referenced this pull request May 4, 2020
…55757)

It's possible for a constant_keyword to have a 'null' value before any documents
are seen that contain a value for the field. In this case, no documents have a
value for the field, and 'exists' queries should return no documents.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>bug :Search/Search Search-related issues that do not fall into other categories v7.7.1 v7.8.0 v8.0.0-alpha1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

exists query returns no documents for a no-value constant_keyword

5 participants