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

[Question] Native query using terms filter #107

Closed syncush closed 5 years ago

syncush commented 5 years ago

GeoServer version: v2.15.2 elasticgeo version: v2.15.1-RC1 Elasticsearch version: v6.4.2

I would like to pass a native query to my elasticsearch that uses the terms filter, I have tried the following

my query is :

const query = {"terms":{"source": ["1", "2"]}}
const queryString = 'q:' + JSON.stringify(query).replace(',', '\\,');
https://mygeoserver.com/geoserver/workspace/wms?........&viewparams=${encodeURI(queryString)}

I have used encodeURI because without it I recieve an error indicating there are invalid characters in my queryString.

The error I receive is the following

<ServiceException code="org.geoserver.wms.map.GetMapKvpRequestReader">
1 layers requested, but found 2 view params specified
</ServiceException>

Is the error I am receiving is related to directly to elasticgeo? is it possible to use the terms filter in native query?

sjudeng commented 5 years ago

See if it works to encode just the query body:

const queryString = JSON.stringify(query).replace(',', '\\,');
const url = `https://mygeoserver.com/geoserver/workspace/wms?........&viewparams=q:${encodeURI(queryString)}`
syncush commented 5 years ago

Hi @sjudeng thank you for your answer but unfortunately, I still get the same error.

syncush commented 5 years ago

I fixed it, I just changed the encodeURI function to encodeURIComponent.

const query = {"terms":{"source": ["1", "2"]}}
const queryString = 'q:' + JSON.stringify(query).replace(',', '\\,');
https://mygeoserver.com/geoserver/workspace/wms?........&viewparams=${encodeURIComponent(queryString)}

Issue can be closed.

sjudeng commented 5 years ago

Great thank you for reporting back