-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Allow scripts to handle missing mappings gracefully #22056
Comments
You can use the containsKey method on the doc to see if the field exists (
|
Ah interesting, is that documented anywhere? My natural inclination was to try a null check ( Also, is there an equivalent to |
The nice thing about throwing the exception is that you know why the you got null. I think this one is probably best solved with documented examples or a change to the error message in the exception or both. I don't know about expressions though. |
I can't remember off the top of my head for expressions, but if I had to guess it will just be 0.0 since expressions assumes all values are doubles and can't represent null. Edit: I take that back. I think it will be a run-time error where it can't bind the appropriate field. |
@jdconrad I'm not sure I follow. When I write an expression script that accesses a field with no mapping in the index, I get the same error, not a value of 0.0 or null. @nik9000 Re-reading Ryan's comment I realized he mentioned that |
Yes, my first comment was incorrect about expressions, hence the edit :) All the 'doc' classes extend Map, and the get method is overridden to have that error instead of returning null. Using containsKey will use the default Map method, so the error won't appear. |
Ah, I missed the edit :) Well, I'd be ok with just improving the docs, throwing an error on a missing key just felt a little strange to me. It would be nice if we had a way to handle this gracefully with expressions as well though. |
Agree completely about the documentation. It's on a long list of things to help with scripting. |
Nice, this has solved my problem. |
This just needs to be part of the documentation update. |
This commit adds a documentation note about the behavior when trying to access docvalues for a field which does not exist in mappings. closes elastic#22056
This commit adds a documentation note about the behavior when trying to access docvalues for a field which does not exist in mappings. closes #22056
This commit adds a documentation note about the behavior when trying to access docvalues for a field which does not exist in mappings. closes #22056
Thanks so much this really help solve my problem !!!! |
Elasticsearch version: 6.0, 5.x
Plugins installed: none
JVM version: 1.8.0_60
OS version: OSX El Capitan
Description of the problem including expected versus actual behavior:
If a script attempts to access a field that does not exist in the mappings of one or more target indices, you'll get an error saying "Field [foo] does not exist in mappings".
Steps to reproduce:
When querying wildcard index patterns, it's quite possible that some indices will contain mappings that others do not. It would be nice if the user had the option to handle the missing fields gracefully within the script instead of blowing up the entire request.
The text was updated successfully, but these errors were encountered: