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
169 stars 85 forks source link

Elastic search aggregations through view params not working #99

Closed Dp024 closed 5 years ago

Dp024 commented 5 years ago

I am using in ajax call var ajax = $.ajax({ method: "POST", url : URL,//this is url of server dataType : 'jsonp', jsonpCallback : 'getJson', data: { viewparams:'a:{"aggs": { "uniq_countries": {"terms": {"field": "properties.ISO_N3.keyword"\,"size": 500}\,"aggs": {"aggs_values": {"avg": {"field": "properties.value"}}}}}\,"size": 0}' }) when i send the request to the server i got the error like <?xml version="1.0" ?> <ServiceExceptionReport version="1.2.0" xmlns="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/wfs/1.0.0/OGC-exception.xsd">

mil.nga.giat.data.elasticsearch.FilterToElasticException: Unable to parse aggregation Unable to parse aggregation Can not deserialize instance of java.util.LinkedHashMap out of VALUE_NUMBER_INT token at [Source: {"aggs": { "uniq_countries": {"terms": {"field": "properties.ISO_N3.keyword","size": 500},"aggs": {"aggs_values": {"avg": {"field": "properties.value"}}}}},"size": 0}; line: 1, column: 156] (through reference chain: java.util.LinkedHashMap["size"]) Note: The aggreagation query in view params giving the appropriate results when this query send to the elastic search through kibana. The fields used in the query properties.ISO_N3 is String type. properties.value is Float type. Please help me to solve this error.
sjudeng commented 5 years ago

The implementation assumes that the aggregation values are all maps defining the aggregation/aggregations (see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations.html#_structuring_aggregations).

{
    "aggregation_name1": {
        ...
    },
    "aggregation_name2": {
        ...
    }
}

So the size=0 item in the outer map causes the problem. Is the size parameter in the outer aggregation body valid/needed?

Dp024 commented 5 years ago

Thank you for the help. size parameter not related to aggregation. it's related to POST index/type/_search?size=0{ }. I sent size parameter in elastic search query through kibana like POST index/type/_search {"query": {"bool": {"filter": [ {"term": { "properties.time_id": "2019"}}]}}, "aggs": {"uniq_countries": {"terms": {"field": "properties.ISO_N3.keyword","size": 500}, "aggs": {"aggs_values": {"avg": {"field": "properties.value"}}}}},"size": 0 } . this query working fine in kibana.
I am using cql_filter for properties.time_id and it is part of URL. so i need only aggregation part. i removed size parameter and send the request to geoserver using viewparams like viewparams:'a:{"aggs": { "uniq_countries": {"terms": {"field": "properties.ISO_N3.keyword"\,"size": 500}\,"aggs": {"aggs_values": {"avg": {"field": "properties.value"}}}}}}' then i got the error like status line [HTTP/1.1 400 Bad Request] root_cause->named_object_not_found_exception, reason-> [1:4644] unable to parse BaseAggregationBuilder with name [uniq_countries]: parser not found could you please help on this.

sjudeng commented 5 years ago

The aggregation viewparam value should be the aggregation content, where the keys in the outermost element are the aggregation name(s). So in this case try {"uniq_countries": {"terms": {"field": "properties.ISO_N3.keyword"\, "size": 500}\, "aggs": {"aggs_values": {"avg": {"field": "properties.value"}}}}}

Dp024 commented 5 years ago

I tried with viewparams:'a:{"uniq_countries": {"terms": {"field": "properties.ISO_N3.keyword"\, "size": 500}\, "aggs": {"aggs_values": {"avg": {"field": "properties.value"}}}}}' I got the following error java.lang.RuntimeException: java.io.IOException: Error executing count search java.io.IOException: Error executing count search Error executing count search Unrecognized field "doc_count_error_upper_bound" (class mil.nga.giat.data.elasticsearch.ElasticAggregation), not marked as ignorable (one known property: "buckets"]) at [Source: org.apache.http.nio.entity.ContentInputStream@49e84059; line: 1, column: 201] (through reference chain: mil.nga.giat.data.elasticsearch.ElasticResponse["aggregations"]->java.util.LinkedHashMap["uniq_countries"]->mil.nga.giat.data.elasticsearch.ElasticAggregation["doc_count_error_upper_bound"])

could you please help on this.

sjudeng commented 5 years ago

This was fixed in https://github.com/ngageoint/elasticgeo/pull/92. It'll be included in the next release. In the meantime if you're able to build the plugin using the latest master branch then it should resolve this error.

sjudeng commented 5 years ago

Fixed in 2.14.2-RC1.