-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Scripted fields must reference values via params when filtering #8642
Scripted fields must reference values via params when filtering #8642
Conversation
@stacey-gammon If we can get this done, this should go into 5.0.0. Painless is a pretty big part of 5.0 for the whole stack, so it being broken in Kibana is a big deal. |
@@ -114,13 +114,13 @@ describe('Filter Manager', function () { | |||
checkAddFilters(0, null, 3); | |||
expect(appState.filters).to.have.length(2); | |||
|
|||
let scriptedField = {name: 'scriptedField', scripted: true, script: 1}; | |||
let scriptedField = {name: 'scriptedField', scripted: true, script: 1, lang: 'painless'}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a separate test for the painless scripted field, instead of modifying the existing test? I think we're still supporting Groovy, but recommending painless.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, I don't think this is a very good test, at least for this particular issue. I investigated adding a test that would actually send the query to ES but abandoned the endeavor as too time consuming (for the moment) since this is supposed to get into 5.0. The original test didn't catch this bug so I find it somewhat useless (or at least geared towards verifying something else). What if the ES syntax changes in the future? We'd end up in the same situation and end up with a similar fix - updating both test and function. So adding an extra, similar test is just an extra spot we'd have to manually adjust.
I can still add the test if you feel strongly about it, because there isn't any harm in it. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with you that it's a poor test. I don't feel very strongly regarding it.
I ran through the rest of the aggs in the vis editor. The only one where filtering via clicking the chart seems to work is the terms agg. |
@Bargs I'm pretty sure that is a separate, existing issue. The error is around the 'gte' portion of the below request we are sending to ES: "inline" : "(doc["bytes"].value * -1)>=gte && (doc["bytes"].value * -1)<lt" That syntax looks invalid. All these bugs do concern me though and make me think that spending some more time on tests that would catch these issues is worth some delay. Do you feel I should address all painless, scripted, filtered field issues in this one PR or break them up? I think I would prefer to break them up. Then, if I can figure out how to add some round trip tests to verify ES can properly consume our syntax, I can add specific tests for each specific issue. When you say "the rest of the aggs in the vis editor" do you mean that also non-scripted field filtering isn't working in that context? Regular fields seem to work for me, just painless scripted fields. |
The range filter works ok with a lucene expression scripted field, so I think it's new with painless. I think it would be nice to address all of the painless filter issues in this PR if we can. If we find out one of these errors are really a different beast altogether we could spin it off though. @LeeDr's functional tests have typically been great at finding this sort of bug. What's really hurting us here is that we don't have any functional tests for scripted fields. He just created an issue for that the other day #8594. I was going to try to tackle that as soon as I had time, but if you get to it first that would be awesome!
Specifically painless scripted fields |
So I just tested the query with the script based range filter and it seems to be caused by the same Fails
Works
|
Updating
params. when the lang is painless fixes the errors with histogram and range aggregations. Still need to track down the issue with the date histogram though.
|
Ah, consider foot properly placed in mouth. Thanks for tracking that second error down. I've updated the pull request and will also investigate the date histogram stuff. I'll update this PR with the fixes first, and then once everything is working, see if I can add functional tests. That way we'll at least be ready to go with the fix if the tests take longer than expected. |
I did some investigating into the date errors as well. The date filter is also a range filter under the hood, so the ES error stems from the fact that the params object for this date filter has a
I think we could just filter out the format key from params, I'm not sure if there's a more appropriate way to handle it or not. That fixes the actual error, but the "Invalid date" label on the filter is a bit more complicated. There are a bunch of "filter mappers" in |
c909c45
to
8db3552
Compare
acaa91a
to
3fc6b90
Compare
Alrighty, I fixed some of the label issues, the compile errors, and the test failures. There are still a couple issues with the filter bar labels (see #8660) but I didn't want to include them in a hotfix, esp since some of those issues exist with non-scripted fields as well. For a hotfix PR, this ended up being a wider scope than I originally hoped, and I'm not super confident that this doesn't introduce any issues, but I don't have a better idea, unless we want to wait for more tests to be added around this (which I can work on today, but tbd when they would be ready). |
@@ -33,8 +33,11 @@ export default function buildRangeFilter(field, params, indexPattern, formattedV | |||
lt: '<', | |||
}; | |||
|
|||
params = _.pick(params, (val, key) => { return key in operators; }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would create a new variable instead of modifying params.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
expect(filter.script.script.lang).to.eql('expression'); | ||
expect(filter.script.script.inline).to.eql(expectedInline); | ||
expect(filter.script.script.params.value).to.eql('>=1 <=3'); | ||
expect(filter.meta.field).to.eql('script number'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why the old test would fail, could you explain?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm reverting this change, indeed it's not needed. I arrived here because initially I updated the field to match non-scripted, so it was "[start date] to [end date]" rather than ">=[start date] <=[end date]". When the test failed the params were out of order, a side affect I thought of my updated code and then I thought, how silly that the order of params matters, so adjusted the check to be like this. On second thought though, it must have failed because of the string comparison, not because of the order of params (I'm guessing the comparator is smart enough to handle that). Since I reverted the new format I'm reverting this whole file.
@@ -14,8 +14,7 @@ define(function () { | |||
if (filter.meta.formattedValue) { | |||
value = filter.meta.formattedValue; | |||
} else { | |||
value = filter.script.script.params.value; | |||
value = field.format.convert(value); | |||
value = '' + filter.script.script.params.value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately removing the call to convert
has the side effect of preventing field formatters from taking effect. For instance, in the screenshot below both bytes
and Double Bytes
are configured with a bytes field formatter, but only the non-scripted bytes field is display correctly.
I think we need to detect when the script filter is a range, and do what map_range.js is doing in those cases https://github.com/Bargs/kibana/blob/cd760781b202e74c0dc83edcd8e36341043a42f7/src/ui/public/filter_bar/lib/map_range.js#L22-L22
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whew, good catch! Reverting the label changes - will tackle that in a separate PR.
3fc6b90
to
059c138
Compare
Need to use params.value instead of value. Fixes elastic#8404 Add params prefix in another spot for painless scripted fields Fix date histogram with scripted fields Remove format: epoch_millis so the script compiles. I am not 100% confident of the side affect from this (it’s used for non-scripted fields, but I’m not sure where I would put it for scripted fields, or if it’s needed). At any rate, it appears that formatting settings for scripted fields is still being honored, even after removing it from params.
059c138
to
7cdb74d
Compare
We're going to handle #8642 (comment) and #8660 separate PRs, so this LGTM. |
--------- **Commit 1:** Fix our request to ES for filtering on scripted fields Need to use params.value instead of value. Fixes #8404 Add params prefix in another spot for painless scripted fields Fix date histogram with scripted fields Remove format: epoch_millis so the script compiles. I am not 100% confident of the side affect from this (it’s used for non-scripted fields, but I’m not sure where I would put it for scripted fields, or if it’s needed). At any rate, it appears that formatting settings for scripted fields is still being honored, even after removing it from params. * Original sha: 7cdb74d * Authored by Stacey Gammon <[email protected]> on 2016-10-12T14:54:23Z
--------- **Commit 1:** Fix our request to ES for filtering on scripted fields Need to use params.value instead of value. Fixes #8404 Add params prefix in another spot for painless scripted fields Fix date histogram with scripted fields Remove format: epoch_millis so the script compiles. I am not 100% confident of the side affect from this (it’s used for non-scripted fields, but I’m not sure where I would put it for scripted fields, or if it’s needed). At any rate, it appears that formatting settings for scripted fields is still being honored, even after removing it from params. * Original sha: 7cdb74d * Authored by Stacey Gammon <[email protected]> on 2016-10-12T14:54:23Z
Created a new ticket for the boolean filter issue #8677 |
[backport] PR #8642 to 5.x
[backport] PR #8642 to 5.0
--------- **Commit 1:** Fix our request to ES for filtering on scripted fields Need to use params.value instead of value. Fixes elastic#8404 Add params prefix in another spot for painless scripted fields Fix date histogram with scripted fields Remove format: epoch_millis so the script compiles. I am not 100% confident of the side affect from this (it’s used for non-scripted fields, but I’m not sure where I would put it for scripted fields, or if it’s needed). At any rate, it appears that formatting settings for scripted fields is still being honored, even after removing it from params. * Original sha: 24622fad83d0388a38d9557e4a1ff7b80ec27083 [formerly 7cdb74d] * Authored by Stacey Gammon <[email protected]> on 2016-10-12T14:54:23Z Former-commit-id: 4b54dc6
[backport] PR elastic#8642 to 5.x Former-commit-id: e080b85
Groovy and expression should continue to use 'value'.
This could have been better refactored but given the timing of the release and that this is a last minute change, that I am guessing will go into the next RC, I wanted the diffs to be as small as possible.
Closes #8404