koopjs / koop-provider-elasticsearch

A provider for koop that can connect to one or more elastic search instances and turn indices/aliases into individual feature services.
Apache License 2.0
13 stars 4 forks source link

Unhandled geo-point field type format #28

Closed shygnome closed 3 years ago

shygnome commented 3 years ago

I am currently working with geo-point data in ES, and my geo_point data have a format like this [1].

PUT my-index-000001/_doc/1
{
  "text": "Geo-point as an object",
  "location": { 
    "lat": 41.12,
    "lon": -71.34
  }
}

When I gave it a try, accessing the FeatureServer, it gave me this error.

...
{"message":"Failed to parse {\"_index\":\"INDEX_NAME\",\"_type\":\"_doc\",\"_id\":\"DOC_ID\",\"_score\":1,\"_source\":{\"@timestamp\":TIMESTAMP,\"ident\":\"IDENT\",\"location.lon\":LONGITUDE,\"location.lat\":LATITUDE}} with following error:","level":"warn"}
{"level":"error"}
...

I found out that the location object is flattened and split into two different fields (location.lon and location.lat).

I assume that the error comes from these section of code at hitConverter (link)

               if(Array.isArray(feature.geometry)){

                    // If the index config is set to allow multiple points. If it isn't, then only the first point is used.
                    if (indexConfig.allowMultiPoint === true) {
                        pointType = "MultiPoint";
                        coords = [];
                        if (!isNaN(feature.geometry[0])){ // case where we allow multipoint but this is a single point
                            coords.push(feature.geometry);
                        } else {
                            feature.geometry.forEach((geom) => {
                                if(geom.hasOwnProperty('lon')){
                                    coords.push([geom.lon, geom.lat]);
                                } else {
                                    coords.push(geom);
                                }
                            });
                        }
                    } else {
                        // The index was not configured for multipoint, so only the first point is used.
                        pointType = "Point";
                        if(feature.geometry[0].hasOwnProperty('lon')){
                            coords = [feature.geometry[0].lon, feature.geometry[0].lat];
                        } else {
                            coords = feature.geometry;
                        }
                    }
                } else {
                    pointType = "Point";
                    coords = feature.geometry.split(",").map( coord => {
                        return parseFloat(coord);
                    }).reverse();
                }

This block assumes that the incoming hit with single point has a format of string only (something like "41.12,-71.34").

Is this truly an unhandled format? Or is there any extra configuration in my format case? Or should I change the format to string? Thank you :blush:

Reference

[1] Geo-point field type

dhatcher commented 3 years ago

@shygnome Yep that is a bug. We weren't handling geo_point with lat/lon properties if they weren't set as multi-point. There's a pull request with that fix moving through now. Thanks for catching it!

rgwozdz commented 3 years ago

@shygnome - we've published a fix with 2.2.2.

shygnome commented 3 years ago

@shygnome - we've published a fix with 2.2.2.

@rgwozdz @dhatcher - Nice, it's working. Great work guys! You can close this issue.

zakhtar1998 commented 2 years ago

@shygnome i am currently experiencing this problem in the latest Koop version and when i type the validate command i get the following:

image

Have you tried querying the geo_point in the latest koop version?