Skip to content

ESQL: Implement network_direction function#136133

Merged
MattAlp merged 35 commits intoelastic:mainfrom
MattAlp:network_direction_esql_function
Oct 22, 2025
Merged

ESQL: Implement network_direction function#136133
MattAlp merged 35 commits intoelastic:mainfrom
MattAlp:network_direction_esql_function

Conversation

@MattAlp
Copy link
Contributor

@MattAlp MattAlp commented Oct 7, 2025

@MattAlp MattAlp requested a review from a team as a code owner October 7, 2025 20:56
@elasticsearchmachine elasticsearchmachine added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label Oct 7, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-analytical-engine (Team:Analytics)

@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/kibana-esql (ES|QL-ui)

@elasticsearchmachine
Copy link
Collaborator

Hi @MattAlp, I've created a changelog YAML for you.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 7, 2025

@github-actions
Copy link
Contributor

github-actions bot commented Oct 7, 2025

ℹ️ Important: Docs version tagging

👋 Thanks for updating the docs! Just a friendly reminder that our docs are now cumulative. This means all 9.x versions are documented on the same page and published off of the main branch, instead of creating separate pages for each minor version.

We use applies_to tags to mark version-specific features and changes.

Expand for a quick overview

When to use applies_to tags:

✅ At the page level to indicate which products/deployments the content applies to (mandatory)
✅ When features change state (e.g. preview, ga) in a specific version
✅ When availability differs across deployments and environments

What NOT to do:

❌ Don't remove or replace information that applies to an older version
❌ Don't add new information that applies to a specific version without an applies_to tag
❌ Don't forget that applies_to tags can be used at the page, section, and inline level

🤔 Need help?

import java.util.Arrays;
import java.util.List;

public class NetworkDirectionUtils {
Copy link
Contributor

Choose a reason for hiding this comment

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

Despite being an utility, this class seems very specific to the esql function; it is not a general-purpose network utility. Is it possible to avoid adding it to server?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After exploring alternatives, like placing it within libs, it seems that the dependency on CIDRUtils and InetAddresses means that moving this elsewhere would require a larger refactor/org of the networking-related utility classes.

@mouhc1ne
Copy link
Contributor

I don't know if there is such a thing as aliases in ESQL scalar functions, but if there was, would be nice to only have to write netdir instead of the full network_direction.

@Override
public String paramName(boolean blockStyle) {
return name + (blockStyle ? "Block" : "Vector");
return name + "Block";
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure this is needed?

I ran ./gradlew :x-pack:plugin:esql:compileJava locally on this repo, with and without this change, and I don't see any generated classes change. I think it isn't needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe that's because I've since changed the signature and annotations on the process method, which no longer triggers the faulty codegen.

In order to reproduce, you should be able to check out the earlier commit 3129e57, revert this change, and see what happens when you attempt to compile.

Nik should be able to confirm when he's back - as I understand, BlockArguments can't be represented as Vectors by definition, which is why the reproducer will create valid control flow but mistakenly refer to a ${name}Vector on one line while referencing the ${name}Block earlier.

Copy link
Contributor

Choose a reason for hiding this comment

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

I made this change in my local copy, then ran the gradle command from earlier. The result is captured in the screenshot.

image

Looks like the semantics are broken since addRawVector method is called and passed a valuesBlock instead of valuesVector. Not that it matters a lot, I mean compiler is happy, and method is no-op anyways so param can be called anything. It just breaks the semantics, that's all. You're right that vectors don't mean much for the block arg class, but at least the current way both the method and its param name are in sync.

Copy link
Contributor

Choose a reason for hiding this comment

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

@nik9000 or @dnhatn may have an opinion on this.

Copy link
Member

Choose a reason for hiding this comment

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

That screenshot looks fine - though I had just asked @mouhc1ne about removing this method entirely because it's not called. Let me have a look at the rest of it.

Copy link
Member

Choose a reason for hiding this comment

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

OK! I understand now. @MattAlp does indeed need this change. We don't have any other functions that'd bump into this. But, it does, indeed, make a lame parameter name on those methods. But, like 20 minutes ago, I requested skipping generating these methods anyway. So I guess that's fine.

@MattAlp
Copy link
Contributor Author

MattAlp commented Oct 14, 2025

I don't know if there is such a thing as aliases in ESQL scalar functions, but if there was, would be nice to only have to write netdir instead of the full network_direction.

It looks like there is, https://github.com/mattalp/elasticsearch/blob/24d8f307acd7ed2e249774899a94cd0135464b16/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/EsqlFunctionRegistry.java#L457

@MattAlp MattAlp requested a review from mouhc1ne October 14, 2025 15:32
@MattAlp MattAlp requested a review from nik9000 October 14, 2025 15:41
@Override
public String paramName(boolean blockStyle) {
return name + (blockStyle ? "Block" : "Vector");
return name + "Block";
Copy link
Member

Choose a reason for hiding this comment

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

OK! I understand now. @MattAlp does indeed need this change. We don't have any other functions that'd bump into this. But, it does, indeed, make a lame parameter name on those methods. But, like 20 minutes ago, I requested skipping generating these methods anyway. So I guess that's fine.

@MattAlp MattAlp merged commit fc7ae8e into elastic:main Oct 22, 2025
34 checks passed
fzowl pushed a commit to voyage-ai/elasticsearch that referenced this pull request Nov 3, 2025
Replicates the network direction enrichment processor's functionality

---------

Co-authored-by: elasticsearchmachine <infra-root+elasticsearchmachine@elastic.co>
couvq added a commit to elastic/kibana that referenced this pull request Feb 19, 2026
…#250894)

Closes elastic/streams-program#569

## Description
This PR introduces a `network_direction` processor to Streamlang which
calculates the network direction given a source IP address, destination
IP address, and a list of internal networks. It uses the
[network_direction](https://www.elastic.co/docs/reference/enrich-processor/network-direction-processor#supported-named-network-ranges)
processor for ingest pipeline transpilation and it uses the new
[NETWORK_DIRECTION](elastic/elasticsearch#136133)
function for ES|QL transpilation.

## Demo

https://github.com/user-attachments/assets/5e9807ad-37e5-4e7b-8b00-7df8b318f2cb

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
ersin-erdal pushed a commit to ersin-erdal/kibana that referenced this pull request Feb 19, 2026
…elastic#250894)

Closes elastic/streams-program#569

## Description
This PR introduces a `network_direction` processor to Streamlang which
calculates the network direction given a source IP address, destination
IP address, and a list of internal networks. It uses the
[network_direction](https://www.elastic.co/docs/reference/enrich-processor/network-direction-processor#supported-named-network-ranges)
processor for ingest pipeline transpilation and it uses the new
[NETWORK_DIRECTION](elastic/elasticsearch#136133)
function for ES|QL transpilation.

## Demo

https://github.com/user-attachments/assets/5e9807ad-37e5-4e7b-8b00-7df8b318f2cb

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Analytics/ES|QL AKA ESQL >enhancement ES|QL-ui Impacts ES|QL UI Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v9.3.0

5 participants