-
Notifications
You must be signed in to change notification settings - Fork 25k
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
Strict Type Checking on Import (or strict type usage for scripts) #30211
Comments
@OlivierPetri, which version of Elasticsearch are you running? Knowing the script context In Elasticsearch 6.2.2, I see the expected behavior. Assuming this is for search-response-time scripting, I've re-created your example with what I see. Let me know if this does not align with your use-case.
returns:
Two things to note about the above example that differs from the two other expressions that were shared.
|
Pinging @elastic/es-core-infra |
Regarding your feature request for stricter validation, I forgot to mention that we do have this for numeric mapping types. Please check out https://www.elastic.co/guide/en/elasticsearch/reference/6.2/coerce.html for examples |
Hi there, and thanks for your kind reply. I confirm that However the doc notation cannot be used in update or update by query statements as stated here and here. This means, that you have to do it manualy I will rerun my tests and come back here, but from what I observed, coercion did not work by default. I'll be back later today. |
@OlivierPetri ah, I see. Since this is an update-script, it does not have access doc-values. I believe that the real issue here is that errors like this should come up at compilation-time, rather than runtime. I believe the explicit integer parsing is the only option at the moment |
Allright and hello again. So from what I found, "coerce = false" just enforces what I named "STRICT" in my proposal, so an integer field has to be inserted as a json integer, and "coerce = true" does what I dubbed "LEGACY": It accepts a quoted number as an integer, but it will not cast it to an integer (which is what I'd understand as "coercion"), but retain the string value. So with "coerce=true" and the input I gave above, I'll end up with:
With this, And sorry for describing this behaviour for Hey, thank you all for the excellent work and your lightening fast responsiveness! |
you're welcome @OlivierPetri, thanks for bearing with the lack of compile-time checking around this! This will be fixed over time, as was mentioned in #30210 (comment). |
Describe the feature:
Currently ES will check the format of input data against the field type, but it does not stick to the specified type when supplying field content to scripts (see example below).
This leads to confusing results and hard to track bugs in client applications.
Desired feature:
Implement different level of type checking:
STRICT : Do not accept "123" for numeric input, only 123.
BEST_EFFORT: Convert "123" to 123 (desired default behaviour).
LEGACY: Current behaviour.
Alternatively controle (and cast!) document fields when handed to scripts (see below).
Example for current behaviour.
Given the following mapping:
and the following input
PUT sumtest/doc/1
{
"NRA" : 12,
"NRB" : 34
}
PUT sumtest/doc/2
{
"NRA" : "12",
"NRB" : "34"
}
The script expression
doc['NRA'] + doc['NRB']
will return 46 for item 1 and "1234" for item 2. The second result ist quite surprising for unsuspecting users.
The expression
ctx._source.NRA + ctx._source.NRB
yields the same result.
The text was updated successfully, but these errors were encountered: