Skip to content
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

Add long flavored script field #59721

Merged
merged 4 commits into from Jul 17, 2020

Conversation

nik9000
Copy link
Member

@nik9000 nik9000 commented Jul 16, 2020

This adds the long runtime type to script fields and implements doc
values, field data, the term and exists query.

Relates to #59332

This adds the `long` runtime type to `script` fields and implements doc
values, field data, the `term` and `exists` query.
@nik9000 nik9000 requested a review from javanna July 16, 2020 18:42
@nik9000 nik9000 added the :Search/Search Search-related issues that do not fall into other categories label Jul 16, 2020
@elasticmachine
Copy link
Collaborator

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

@elasticmachine elasticmachine added the Team:Search Meta label for search team label Jul 16, 2020
@javanna javanna mentioned this pull request Jul 16, 2020
30 tasks
@javanna
Copy link
Member

javanna commented Jul 17, 2020

run elasticsearch-ci/1

Copy link
Member

@javanna javanna 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 some comments, I like it ;)

return count;
}

protected final void add(long v) {
Copy link
Member

Choose a reason for hiding this comment

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

does it need to be protected? Also maybe rename to something like collectValue ? I find it weird to call add against the script itself

Copy link
Member Author

Choose a reason for hiding this comment

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

does it need to be protected?

I thought so, but I'll take a look.

Also maybe rename to something like collectValue

👍

import java.io.IOException;
import java.util.Arrays;

public final class ScriptLongDocValues extends AbstractSortedNumericDocValues {
Copy link
Member

Choose a reason for hiding this comment

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

you can use SortingNumericDocValues?

Copy link
Member Author

Choose a reason for hiding this comment

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

It'd force me to copy the longs from one array to the other rather than just sort. We already have to copy string because of BytesRef vs String stuff. But here I don't have to copy unless I want to.

Copy link
Member

Choose a reason for hiding this comment

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

I see, makes sense then


@Override
public void setSearchLookup(SearchLookup searchLookup) {
// TODO wire the params from the mappings definition, we don't parse them yet
Copy link
Member

Choose a reason for hiding this comment

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

if you carry the script around you can remove this TODO :)

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

try {
return loadDirect(context);
} catch (Exception e) {
if (e instanceof ElasticsearchException) {
Copy link
Member

Choose a reason for hiding this comment

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

another change that I lost somehow, but this should rather be ExceptionsHelper#convertToElastic . Can you make the same change in the binary one too?

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

@Override
public float matchCost() {
// TODO we don't have a good way of estimating the complexity of the script so we just go with 9000
return 9000f;
Copy link
Member

Choose a reason for hiding this comment

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

Shall we make this a shared constant somewhere, and remove the TODO as that is what we will keep for the time being?

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

@Override
public final String toString(String field) {
if (fieldName().contentEquals(field)) {
return "ScriptFieldExists";
Copy link
Member

Choose a reason for hiding this comment

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

I would be fine with even printing the getSimpleName

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure!

@@ -14,7 +14,7 @@ setup:
temperature:
type: long
voltage:
type: float
type: double
Copy link
Member

Choose a reason for hiding this comment

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

why this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sneaky rounding error in the multiplication in the test script had me waste an hour trying to find out why 5.1 * 10 == 52. Stupid floating point.

@nik9000 nik9000 requested a review from javanna July 17, 2020 17:36
@@ -35,7 +35,7 @@
StringScriptFieldScript newInstance(LeafReaderContext ctx) throws IOException;
}

protected final List<String> results = new ArrayList<>();
private final List<String> results = new ArrayList<>();
Copy link
Member

Choose a reason for hiding this comment

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

thanks! that was my bad after all :D


void mapperXContentBody(XContentBuilder builder, Params params) throws IOException {
builder.field("runtime_type", runtimeType());
builder.field("script", script.getIdOrCode()); // TODO For some reason this doesn't allow us to do the full xcontent of the script.
Copy link
Member

Choose a reason for hiding this comment

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

I no longer remember what this TODO is about. what can we do to address it? and what do we need this method for, again?

Copy link
Member Author

Choose a reason for hiding this comment

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

It spits out the script in the xcontent of the mapper. I think we might want to merge it into the FieldMapper's xcontent rendering. I can have a look in a follow up.

That TODO is basically complaining that I can render the whole script - it won't parse properly if I do. I don't remember why. I'll dig.

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 opened #59813 for the TODO.


public final class RuntimeKeywordMappedFieldType extends MappedFieldType {
public final class ScriptKeywordMappedFieldType extends AbstractScriptMappedFieldType {
Copy link
Member

Choose a reason for hiding this comment

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

++ thanks!

FieldMapper mapper = (FieldMapper) mapperService.documentMapper().mappers().getMapper("field");
assertThat(mapper, instanceOf(ScriptFieldMapper.class));
assertEquals(Strings.toString(mapping("long")), Strings.toString(mapperService.documentMapper()));
}
Copy link
Member

Choose a reason for hiding this comment

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

maybe adding one of these methods could even be automatic once a new supported field type is added to the map? not sure that it's important now though

Copy link
Member Author

Choose a reason for hiding this comment

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

Its a good idea. We could loop through the list but I kind of like having a method for each one.

Copy link
Member

@javanna javanna left a comment

Choose a reason for hiding this comment

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

left some minors here and there but LGTM

@nik9000 nik9000 merged commit c8b5af9 into elastic:feature/runtime_fields Jul 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Search/Search Search-related issues that do not fall into other categories Team:Search Meta label for search team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants