I think I've replicated your issue since I was not able to generate a geo_point
field in Elasticsearch from ogr2ogr
.
Just to confirm the issue in ogr2ogr I did the following steps to upload a dataset and I was not able to perform the upload as geo_point
but it worked fine as geo_shape
. I'm using docker
to ensure there are no particularities from my set up.
(the dollar sign $
indicates a call from the command line)
$ mapshaper -i ne_10m_airports.shp -o airports.geo.json
- Export the URL to my ES instance
$ export ES_URL="http://user:password@host:port"
$ curl -s "${ES_URL}"
{
"name" : "master.elasticsearch",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "b2zx8N5SQF2RPV63DvbdXg",
"version" : {
"number" : "8.1.0-SNAPSHOT",
"build_flavor" : "default",
"build_type" : "docker",
"build_hash" : "20fbe125b9c9264e8da2e4690a2dde13bc1a26e0",
"build_date" : "2022-02-23T00:17:56.526534263Z",
"build_snapshot" : true,
"lucene_version" : "9.0.0",
"minimum_wire_compatibility_version" : "7.17.0",
"minimum_index_compatibility_version" : "7.0.0"
},
"tagline" : "You Know, for Search"
}
- Generate the index mapping file selecting only a few interesting fields:
$ docker run --rm \
-v ${PWD}:/app \
--network host \
--user "$(id -u):$(id -g)" \
osgeo/gdal:alpine-small-latest \
ogr2ogr -overwrite -lco INDEX_NAME=airports \
-select "scalerank,featurecla,type,name,abbrev,wikidataid" \
-lco NOT_ANALYZED_FIELDS={ALL} \
-lco WRITE_MAPPING=/app/airports.mapping.json \
ES:${ES_URL} \
/app/airports.geo.json
- Format the mapping file for easier editing:
$ cat airports.mapping.json | jq > airports.mapping.pretty.json
- Adjust the mappings file to use a
text
type in the name and a geo_shape
for the geometry
field:
{
"properties": {
"scalerank": { "type": "keyword" },
"featurecla": { "type": "keyword" },
"type": { "type": "keyword" },
"name": { "type": "text" },
"abbrev": { "type": "keyword" },
"wikidataid": { "type": "keyword" },
"geometry": { "type": "geo_shape" }
}
}
- While generating the mapping file an index was created, remove it:
$ curl -X DELETE "${ES_URL}/airports"
$ docker run --rm \
-v ${PWD}:/app \
--network host \
osgeo/gdal:alpine-small-latest \
ogr2ogr -progress -skipfailures\
-select "scalerank,featurecla,type,name,abbrev,wikidataid" \
-lco INDEX_NAME=airports \
-lco MAPPING=/app/airports.mapping.pretty.json \
ES:${ES_URL} \
/app/airports.geo.json
- Execute a sample geospatial search
$ curl -s -X POST "${ES_URL}/airports/_search?size=1" \
-H 'Content-Type: application/json' \
-d '{"query":{"geo_distance":{"distance":"15km","geometry":{"lat":40.4,"lon":-3.5}}}}' |\
jq '.hits.hits[]'
{
"_index": "airports",
"_id": "rlstan8B89IY_3rvfWIm",
"_score": 1,
"_source": {
"ogc_fid": 887,
"geometry": {
"type": "Point",
"coordinates": [
-3.5690266546,
40.4681282734
]
},
"scalerank": 2,
"featurecla": "Airport",
"type": "major",
"name": "Madrid Barajas",
"abbrev": "MAD",
"wikidataid": "Q166276"
}
}
Hope this helps to clarify a successful workflow with ogr2ogr
and Elasticsearch.