ngageoint / elasticgeo

ElasticGeo provides a GeoTools data store that allows geospatial features from an Elasticsearch index to be published via OGC services using GeoServer.
GNU General Public License v3.0
168 stars 85 forks source link

Aggregations - assistance needed #65

Closed jim2 closed 6 years ago

jim2 commented 6 years ago

Hi all - great project. I have WMS and WFS working well on individual features. I'm now trying to get grid aggregations going w/ both WMS/WFS.

This query works for me in elastic: curl -XPOST 'localhost:9200/mydata/_search?size=0' -H 'Content-Type: application/json' -d' { "aggregations" : { "large-grid" : { "geohash_grid" : { "field" : "location", "precision" : 4 } } } } '

But I am unclear how to access the same data as a WFS. The project example lists a sample WFS aggregation:

http://localhost:8080/geoserver/test/ows?service=WFS&version=1.0.0&request=GetFeature &typeName=test:active&bbox=0.0,0.0,24.0,44.0 &viewparams=a:{"agg": {"geohash_grid": {"field": "geo"\, "precision": 3}}}

But when I try: http://localhost:8080/geoserver/cite/ows?service=WFS&version=1.0.0&request=GetFeature&viewparams=a:{"aggregations":{"large-grid":{"geohash_grid":{"field":"location"\,"precision":4}}}}

I don't get anything back. Any advice on how to structure the WFS URL is appreciated!

Similar for WMS:

The example is: http://localhost:8080/geoserver/test/wms?service=WMS&version=1.1.0&request=GetMap &layers=test:active&styles=geohashgrid&bbox=0.0,0.0,24.0,44.0&srs=EPSG:4326 &width=418&height=768&format=application/openlayers &viewparams=a:{"agg": {"geohash_grid": {"field": "geo"\, "precision": 3}}}

And this elastic query works for me: curl -XPOST 'localhost:9200/mydata/_search?size=0' -H 'Content-Type: application/json' -d' { "aggregations" : { "zoomed-in" : { "filter" : { "geo_bounding_box" : { "location" : { "top_left" : "41, -75", "bottom_right" : "40, -74" } } }, "aggregations":{ "zoom1":{ "geohash_grid" : { "field": "location", "precision": 8 } } } } } } '

I tried: http://localhost:8080/geoserver/cite/ows?service=WMS&version=1.1.0&request=GetMap &layers=cite:mydata&styles=geohashgrid&viewparams=a:{"aggregations":{"large-grid":{"geohash_grid":{"field":"location","precision":4}}}}

and I tried: http://localhost:8080/geoserver/cite/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=cite:mydata&bbox=41,-75,40,-74&viewparams=a:{"aggregations":{"zoomed-in":{"filter":{"geo_bounding_box":{"location":{"top_left":"41,-75","bottom_right":"40,-74"}}},"aggregations":{"zoom1":{"geohash_grid":{"field":"location","precision":8}}}}}}

Any help is much appreciated.

I'm running elasticsearch 6.2.2 and geoserver 2.12.2

sjudeng commented 6 years ago

In the WFS example it doesn't look like you've included the layer name (e.g. typeName). Also take out the outer "aggregations" in the body so the viewparams value is just a:{"large-grid":{"geohash_grid":{"field":"location"\,"precision":4}}}.

In the WMS have you created the associated geohashgrid style in GeoServer? Also make sure to escape all commas with a backslash and remove the outer aggregations in the body as mentioned above.

I've also seen with recent Tomcat versions that the query body needs to be url encoded before sending to GeoServer otherwise you'll get the below error. Just encode the viewparams value (e.g. a:{...}) to resolve if this is an issue.

INFO [http-nio-8080-exec-9] org.apache.coyote.http11.Http11Processor.service Error parsing HTTP request header
 Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level.
 java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986
jim2 commented 6 years ago

I did get WMS working with your guidance, thanks so much

However I'm still having trouble w/ WFS. Should it return geometries w/ doc_counts? Right now I'm trying:

http://localhost:8080/geoserver/cite/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=cite:mydata&bbox=40,-75,41,-74&viewparams=a:{"large-grid":{"geohash_grid":{"field":"location"\,"precision":3}}}

But not having much luck. (I didn't need to encode the URL for WMS to work), however I've tried the above with encoded parameters as well to see if that helped, but it didn't . Do I need to escape the commas in the bounding box? (it didn't seem to help)

Thanks for any hints!

sjudeng commented 6 years ago

The query looks okay to me. Are you getting any response or do you see any errors in the GeoServer logs? Is "location" the actual geospatial field as shown in the layer attributes? Depending on how the geometry is stored (geojson, etc.) it can be "location.coordinates" but you'd see that in the later attribute list in GeoServer.

It's worth noting that the WFS output for aggregations currently just includes the raw aggregation data, which when serialized to GML for example will just be the string representation of the object. So it's not currently useful other than to diagnose the aggregation request body. In general the aggregation attribution (inlcuding doc_count and geometry) can vary at least in their location in the response. The current implementation delegates the logic for dealing with the aggregation content down to the process (WPS) level used as part of the style for WMS requests.

jim2 commented 6 years ago

Ah - okay - that makes sense. In that case, I have gotten it to work successfully, using a version=1.1.0 query.. I expected a different return object. All good here. Many thanks!