Skip to content

Add support for script to boolean field mapper #71454

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

Merged
merged 14 commits into from
Apr 12, 2021

Conversation

javanna
Copy link
Member

@javanna javanna commented Apr 8, 2021

Relates to #68984

@javanna javanna added >enhancement :Search/Search Search-related issues that do not fall into other categories v8.0.0 v7.13.0 labels Apr 8, 2021
@javanna javanna requested a review from romseygeek April 8, 2021 08:57
@@ -293,7 +293,7 @@ public void newDynamicDoubleField(ParseContext context, String name) throws IOEx

@Override
public void newDynamicBooleanField(ParseContext context, String name) throws IOException {
createDynamicField(new BooleanFieldMapper.Builder(name), context);
createDynamicField(new BooleanFieldMapper.Builder(name, null), context);
Copy link
Member Author

Choose a reason for hiding this comment

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

I wonder if instead of null we should have some impl of ScriptCompiler that throws UnsupportedOperationException when used.

Copy link
Contributor

Choose a reason for hiding this comment

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

++, either here or in a follow up - it will be useful on the other field mappers as well

MultiFields multiFields, CopyTo copyTo,
boolean hasScript, String onScriptError) {
this(simpleName, mappedFieldType, Collections.emptyMap(), multiFields, copyTo, hasScript, onScriptError);
}
Copy link
Member Author

Choose a reason for hiding this comment

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

if we agree on the new constructors, I think we should try to move all the callers of the ones without the additional parameters to these, otherwise we end up with too many constructors

Copy link
Contributor

Choose a reason for hiding this comment

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

I like pulling out the common behaviour, but maybe we should try and localise this more? Have an intermediate class called ScriptableFieldMapper or something like that?

Copy link
Member Author

Choose a reason for hiding this comment

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

I am not sure it's worth the complexity of one additional intermediate base class, especially as more types will support a script.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair enough - we can probably merge the single analyzer and multiple analyzer constructors at least without causing too much noise.

Copy link
Member Author

Choose a reason for hiding this comment

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

agreed, let's do it as a followup?

Copy link
Contributor

@romseygeek romseygeek left a comment

Choose a reason for hiding this comment

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

I left a couple of suggestions, I'm guessing tests will come in soon now that #71322 has been merged?

MultiFields multiFields, CopyTo copyTo,
boolean hasScript, String onScriptError) {
this(simpleName, mappedFieldType, Collections.emptyMap(), multiFields, copyTo, hasScript, onScriptError);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I like pulling out the common behaviour, but maybe we should try and localise this more? Have an intermediate class called ScriptableFieldMapper or something like that?

runForDoc(docId);
int count = trues + falses;
for (int i = 0; i < count; i++) {
consumer.accept(i >= falses);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need to emit true trues times and then false falses times here? Otherwise we're collapsing things down to a single value where there may be multiple values in the source.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that is what I am doing: count is trues + falses. I emit false until there are falses left, and then trues. I may be missing something though as I don't follow the collapsing concern you mentioned :)

Copy link
Contributor

Choose a reason for hiding this comment

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

duh yes, I am clearly not reading properly today. Maybe add a comment?

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe it's because the code is cryptic. this is some simplification that IntelliJ suggested, I should go back to something more readable although longer.

@javanna javanna marked this pull request as ready for review April 8, 2021 14:37
@elasticmachine elasticmachine added the Team:Search Meta label for search team label Apr 8, 2021
@elasticmachine
Copy link
Collaborator

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

@javanna
Copy link
Member Author

javanna commented Apr 8, 2021

I pushed an update including docs and yaml tests

Copy link
Contributor

@romseygeek romseygeek left a comment

Choose a reason for hiding this comment

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

LGTM!

the document will be rejected with an error.
Scripts are in the same format as their
<<runtime-mapping-fields,runtime equivalent>>. Scripts can only be
configured on `long` and `double` field types.
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't need this last sentence for booleans :)

Copy link
Member Author

Choose a reason for hiding this comment

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

ops

@@ -208,14 +242,21 @@ public Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower
private final boolean indexed;
private final boolean hasDocValues;
private final boolean stored;
private final Script script;
private final FieldValues<Boolean> scriptValues;
private final ScriptCompiler scriptCompiler;
Copy link
Contributor

Choose a reason for hiding this comment

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

One feature freeze is gone I want to look seriously at moving merge to Builder objects, having to carry this stuff around is a real pain.

Copy link
Member Author

Choose a reason for hiding this comment

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

agreed! I am happy to help with that

@@ -293,7 +293,7 @@ public void newDynamicDoubleField(ParseContext context, String name) throws IOEx

@Override
public void newDynamicBooleanField(ParseContext context, String name) throws IOException {
createDynamicField(new BooleanFieldMapper.Builder(name), context);
createDynamicField(new BooleanFieldMapper.Builder(name, null), context);
Copy link
Contributor

Choose a reason for hiding this comment

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

++, either here or in a follow up - it will be useful on the other field mappers as well

MultiFields multiFields, CopyTo copyTo,
boolean hasScript, String onScriptError) {
this(simpleName, mappedFieldType, Collections.emptyMap(), multiFields, copyTo, hasScript, onScriptError);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Fair enough - we can probably merge the single analyzer and multiple analyzer constructors at least without causing too much noise.

if (script.getIdOrCode().equals("serializer_test")) {
return (T) serializableScript();
return (T)serializableScript();
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I definitely prefer a space here...

Copy link
Member Author

Choose a reason for hiding this comment

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

this was not meant to happen :)

@javanna javanna merged commit 1469e18 into elastic:master Apr 12, 2021
javanna added a commit to javanna/elasticsearch that referenced this pull request Apr 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>enhancement :Search/Search Search-related issues that do not fall into other categories Team:Search Meta label for search team v7.13.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants