Skip to content

[FEATURE]Add geoip function to PPL for IP address geolocation #3038

Closed

Description

@YANG-DB

Description:
We propose adding an geoip function to OpenSearch's Piped Processing Language (PPL) and SQL to provide built-in IP address geolocation capabilities.
This feature would be similar to functionality used in OpenSearch's geospatial feature, enhancing PPL's ability to enrich log data with geographical information based on IP addresses.

Proposed Functionality:

  1. The 'geoip' function should take an IP address as input and return geographical information.
  2. It should support both IPv4 and IPv6 addresses.
  3. The function should return multiple fields including country, region, city, latitude, longitude, and others as available.
  4. It should allow users to specify which geolocation fields to include in the output.
  5. The function should use a regularly updated IP geolocation database for accuracy.

Example Usage:

... | eval geolocation = geoip(ip_field)

This would add a new field 'geolocation' with all available location information for the IP address in 'ip_field'.

... | eval country = geoip(ip_field, "country")
... | eval lat = geoip(ip_field, "lat"), lon = geoip(ip_field, "lon")

This would add new fields with specific geolocation information.

... | eval location_info = geoip(ip_field, "country,region,city,lat,lon")

This would add a new field 'location_info' with multiple pieces of geolocation data.

Additional considerations

  • Allow for using the geospatial opensearch plugin for the ip to geo resolving

Related resources

Activity

  1. added
    enhancement
    PPL
    on Sep 16, 2024
  2. dblock commented on Oct 7, 2024

    @dblock
    Member

    [Catch All Triage - 1, 2, 3, 4]

  3. kenrickyap commented on Oct 18, 2024

    @kenrickyap
    Contributor

    Am in the process of implementing this

  4. kenrickyap commented on Oct 24, 2024

    @kenrickyap
    Contributor

    Hi @YANG-DB ,

    What was the intended method of leveraging the geospatial plugin?

    Following the example of the inclusion of the job-scheduler and ml-commons plugin, I have been trying to import it directly into the project but noticed that the published geospatial plugin on maven has no jar. As such it does not seem possible to directly import the plugin. Is this assumption correct?

    If so then, my current plan is to call the endpoint that the geospatial plugin exposes in OpenSearch documented here and communicate with it using the OpenSearchRestClient. Would this be a good path forward? or am I missing something that would make it possible to expose the geospatial plugin?

    Thanks!

  5. changed the title [-][FEATURE]Add `iplocation` function to PPL for IP address geolocation[/-] [+][FEATURE]Add `geoip` function to PPL for IP address geolocation[/+] on Nov 2, 2024
  6. andy-k-improving commented on Nov 12, 2024

    @andy-k-improving
    Contributor

    Hi, @YANG-DB
    After a few discovery and feasibility checks, we have updated our approach, the below are the high-level plan along with the proposed code changes.
    Can you have a look and advise?

    High-level idea:

    • Create a new ActionType with logic on Geo-Spatial plugin to expose a new action which takes a IP string and return the appropriate Geo detail.
    • Update existing SQL plugin accordingly to invoke the call on nodeClient with the newly created Geo-Spatial action for the geoip function.

    Proposed code changes:

    GeoSpatial:

    • Create a new TransportAction and register it accordingly:
      • Create a new TransportAction class , which is similar to GetDatasourceTransportAction and the sole purpose of this Action is to process an incoming IP String, with the given provider, then return the appropriate geoSpatial detail fields.
      • Update GeospatialPlugin.getAction( ) class to register the newly created action.
    • Create a new sub-module with name geo-spatial-client which has the nodeClientWrapper as the wrapper for the cross-plugin interaction interface, a few ActionType along with appropriate wrapper object to form the API signature for the return type.
    • Update Gradle script to publish geo-spatial-client module as a separate jar.

    SQL module:

    • Update Gradle setting to import geo-spatial-client into OpenSearch sub-module.
    • Override the existing EvalOpeartor processing logic:
      • Create a new OpenSearchEvalOperator class which extends from the existing EvalOperator with an additional class property NodeClient.
      • Update OpernSearchIndex class to override the visitEval( ) method, and return a new OpenSearchEvalOperator instance instead.
      • Update the OpenSearchEvalOperator to perform the following logic when processing geoip function:
        • Reading the incoming ip string
        • Invoke a call on nodeClient with appropriate arguments and timeout value
        • Marshal the response and update the evalMap accordingly
  7. kedbirhan commented on Nov 13, 2024

    @kedbirhan

    we don't even have a way to do basic Ip address lookups, why are you guys working on the next level before even having a basic way to query ip field type??

  8. andy-k-improving commented on Nov 14, 2024

    @andy-k-improving
    Contributor

    Hi @kedbirhan, thanks for the feedback and indeed that make sense.

    For now we are only proposing the high-level changes required for the functionality but not yet reach to the implementation phase.

    I believe by the time we have the design gathered for this ticket, #3145 should already be wrapped to have the IP type support.

    Thanks,

  9. YANG-DB commented on Nov 15, 2024

    @YANG-DB
    MemberAuthor

    @andy-k-improving
    I really like this idea - can you please create an RFC for the Geospatial plugin suggesting this change?
    We would need their feedback

  10. andy-k-improving commented on Nov 18, 2024

    @andy-k-improving
    Contributor

    @andy-k-improving I really like this idea - can you please create an RFC for the Geospatial plugin suggesting this change? We would need their feedback

    @YANG-DB see below for the RFC on Geo spatial side.
    opensearch-project/geospatial#698
    I will proceed to work on the implementation on GeoSpatial side.

  11. moved this from Todo to In Progress in PPL Commandson Nov 30, 2024
  12. added
    catch-all acknowledged
    on Jan 7, 2025
  13. andy-k-improving commented on Jan 23, 2025

    @andy-k-improving
    Contributor

    The actual PR on SQL repo: #3228

  14. removed
    catch-all acknowledged
    on May 30, 2025
  15. LantaoJin commented on Jun 16, 2025

    @LantaoJin
    Member

    resolved by #3604

  16. moved this from Not Started to Done in PPL Trackeron Jun 16, 2025
  17. moved this from In Progress to Done in PPL Commandson Jun 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    PPLenhancement

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions