Script: fields API for IP mapped type#81396
Conversation
Adds support in the scripting fields API for the `ip` mapped type,
including the runtime script type.
Adds a new value object, `IPAddress`, to avoid exposing Java's
`InetAddress`. `InetAddress` may cause name resolution if whitelisted
improperly.
`field('ip')`, implemented by `IpDocValuesField` exposes:
`IPAddress get(IPAddress)`
`IPAddress get(int, IPAddress)`
`Iterator<IPAddress> iterator()`
`List asStrings()`
`String asString(String)`
`String asString(int, String)`
`IPAddress` exposes:
`boolean isV4()`
`boolean isV6()`
`String toString()`
Refs: elastic#79105
|
Pinging @elastic/es-core-infra (Team:Core/Infra) |
|
Hi @stu-elastic, I've created a changelog YAML for you. |
jdconrad
left a comment
There was a problem hiding this comment.
This looks good! Please do not commit before addressing the plumbing comment. It's also a huge bummer about how there's two different ways we store IP addresses. I wonder if this is something that can be addressed in the future.
| @Override | ||
| public DocValuesField<?> getScriptField(String name) { | ||
| return new DelegateDocValuesField(new Strings(new IpSupplier(getBytesValues())), name); | ||
| return new IpDocValuesField(getBytesValues(), name); |
There was a problem hiding this comment.
This should take in a ToScriptField and follow our standard plumbing pattern to this point. I think there's a real possibility this may be required for source fallback.
There was a problem hiding this comment.
Gotcha, will fix.
There was a problem hiding this comment.
Good catch, done.
| return builder.apply(lower, upper); | ||
| } | ||
|
|
||
| public static final class IpScriptDocValues extends ScriptDocValues<String> { |
There was a problem hiding this comment.
Just for clarity, this all can be deleted because we use the other version now for doc?
There was a problem hiding this comment.
I moved it to IpDocValuesField.SortedSetIpSupplier. Seemed to make more sense there.
| } | ||
|
|
||
| public boolean isV4() { | ||
| return address instanceof Inet4Address; |
There was a problem hiding this comment.
Big thumbs up for this utility method along with the v6. Annoying that the Java API is like this. (Nothing actionable, just like this solution.)
There was a problem hiding this comment.
Thanks, I had to provide these.
Without these two methods there would be no way for users to determine the version of address.
Adds support in the scripting fields API for the
ipmapped type,including the runtime script type.
Adds a new value object,
IPAddress, to avoid exposing Java'sInetAddress.InetAddressmay cause name resolution if whitelistedimproperly.
field('ip'), implemented byIpDocValuesFieldexposes:IPAddress get(IPAddress)IPAddress get(int, IPAddress)Iterator<IPAddress> iterator()List asStrings()String asString(String)String asString(int, String)IPAddressexposes:boolean isV4()boolean isV6()String toString()Refs: #79105