-
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
Add long flavored script field #59721
Add long flavored script field #59721
Conversation
This adds the `long` runtime type to `script` fields and implements doc values, field data, the `term` and `exists` query.
2896a01
to
5ff1e75
Compare
Pinging @elastic/es-search (:Search/Search) |
run elasticsearch-ci/1 |
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 left some comments, I like it ;)
return count; | ||
} | ||
|
||
protected final void add(long v) { |
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.
does it need to be protected? Also maybe rename to something like collectValue ? I find it weird to call add against the script itself
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.
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 { |
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.
you can use SortingNumericDocValues?
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.
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.
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 see, makes sense then
...ields/src/main/java/org/elasticsearch/xpack/runtimefields/fielddata/ScriptLongFieldData.java
Show resolved
Hide resolved
|
||
@Override | ||
public void setSearchLookup(SearchLookup searchLookup) { | ||
// TODO wire the params from the mappings definition, we don't parse them yet |
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.
if you carry the script around you can remove this TODO :)
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.
👍
try { | ||
return loadDirect(context); | ||
} catch (Exception e) { | ||
if (e instanceof ElasticsearchException) { |
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.
another change that I lost somehow, but this should rather be ExceptionsHelper#convertToElastic . Can you make the same change in the binary one too?
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.
👍
@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; |
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.
Shall we make this a shared constant somewhere, and remove the TODO as that is what we will keep for the time being?
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.
👍
@Override | ||
public final String toString(String field) { | ||
if (fieldName().contentEquals(field)) { | ||
return "ScriptFieldExists"; |
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 be fine with even printing the getSimpleName
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.
Sure!
...ields/src/test/java/org/elasticsearch/xpack/runtimefields/mapper/ScriptFieldMapperTests.java
Show resolved
Hide resolved
...c/test/java/org/elasticsearch/xpack/runtimefields/mapper/ScriptLongMappedFieldTypeTests.java
Show resolved
Hide resolved
@@ -14,7 +14,7 @@ setup: | |||
temperature: | |||
type: long | |||
voltage: | |||
type: float | |||
type: double |
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.
why this?
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.
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.
@@ -35,7 +35,7 @@ | |||
StringScriptFieldScript newInstance(LeafReaderContext ctx) throws IOException; | |||
} | |||
|
|||
protected final List<String> results = new ArrayList<>(); | |||
private final List<String> results = new ArrayList<>(); |
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.
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. |
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 no longer remember what this TODO is about. what can we do to address it? and what do we need this method for, again?
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.
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.
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 opened #59813 for the TODO.
|
||
public final class RuntimeKeywordMappedFieldType extends MappedFieldType { | ||
public final class ScriptKeywordMappedFieldType extends AbstractScriptMappedFieldType { |
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.
++ thanks!
FieldMapper mapper = (FieldMapper) mapperService.documentMapper().mappers().getMapper("field"); | ||
assertThat(mapper, instanceOf(ScriptFieldMapper.class)); | ||
assertEquals(Strings.toString(mapping("long")), Strings.toString(mapperService.documentMapper())); | ||
} |
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.
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
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.
Its a good idea. We could loop through the list but I kind of like having a method for each one.
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.
left some minors here and there but LGTM
This adds the
long
runtime type toscript
fields and implements docvalues, field data, the
term
andexists
query.Relates to #59332