# Geodata with Amazon OpenSearch

[Amazon OpenSearch](https://aws.amazon.com/opensearch-service/) is a managed [OpenSearch](https://opensearch.org/) service that runs and scales your clusters—no infrastructure management needed.

OpenSearch supports [geographic data types](https://docs.opensearch.org/latest/query-dsl/geo-and-xy/index/) like [`geo_point`](https://docs.opensearch.org/latest/query-dsl/geo-and-xy/geodistance/) to calculate distance between IP addresses. This is useful for storing [Fastah API responses](https://www.getfastah.com/docs/v1/ip-geolocation-security-api/understanding-the-api-response).

### Creating Index

Use [`keyword`](https://docs.opensearch.org/latest/mappings/supported-field-types/keyword/) for IP addresses and [`geo_point`](https://docs.opensearch.org/latest/mappings/supported-field-types/geo-point/) for [Fastah's locationData](https://www.getfastah.com/docs/v1/ip-geolocation-security-api/understanding-the-api-response) (SRID 4326):

```json OpenSearch
PUT /ip-addresses
{
  "mappings": {
    "properties": {
      "ip": {
        "type": "keyword"
      },
      "location": {
        "type": "geo_point"
      }
    }
  }
}
```

### Storing Coordinates

Insert IP addresses and coordinates:

```json OpenSearch
// Insert Fastah IP data
POST /ip-addresses/_doc
{
  "ip": "98.97.16.1",
  "location": {"lat": 39.04, "lon": -77.49}
}

POST /ip-addresses/_doc
{
  "ip": "204.152.47.10",
  "location": {"lat": 35.47, "lon": -97.52}
}
```

### Visualization on a Map

Create a map visualization in OpenSearch Dashboards to display the points:

![Figure: Plotting geographical coordinates using Maps in OpenSearch Dashboard](https://files.readme.io/8bd05106f3b5b64a1bea7283733287d2a57951903be1557b31302f2ecd24ff38-Screenshot_2025-12-17_155118.png)
