Geoserver - unable to execute native queries to Elasticsearch indexes

Hello everyone,
I am currently facing an issue with executing native queries to Elasticsearch from GeoServer. I have successfully installed the Elasticsearch extension for GeoServer 2.26 and configured an Elasticsearch data store without any problems. I can publish a layer with the index, visualize it correctly on a map, and perform queries using CQL.

I want to go a bit further and execute native queries as specified in Elasticsearch data store — GeoServer 2.28.x User Manual. Specifically when it comes to using a GetMap XML file. According to the documentation:
Native Elasticsearch queries can be applied in WMS feature requests through a custom rendering transformation, vec:GeoHashGrid, which translates aggregation response data into a raster for display. If supplied, the query is combined with the query derived from the request bbox, CQL, or OGC filter using the AND logical binary operator.

I have successfully run the following curl command with the getMap1.xml file, which uses some test data loaded in Elasticsearch:

curl -X POST -H "Content-Type:text/xml" --data @getMap1.xml "http://localhost:8080/geoserver/wms?request=GetMap&service=WMS&version=1.1.1&styles=&srs=EPSG%3A4326" -o output_image.png

The content of getMap1.xml is as follows, which doesn’t include any native query yet:

<?xml version="1.0" encoding="UTF-8"?>
<ogc:GetMap xmlns:ogc="http://www.opengis.net/ows"
            xmlns:gml="http://www.opengis.net/gml"
            version="1.1.1" service="WMS">
   <StyledLayerDescriptor version="1.0.0">
      <NamedLayer>
        <Name>mytest:mytest</Name>
      </NamedLayer>
   </StyledLayerDescriptor>
   <BoundingBox srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
      <gml:coord><gml:X>-145.15104058007</gml:X><gml:Y>21.731919794922</gml:Y></gml:coord>
      <gml:coord><gml:X>-57.154894212888</gml:X><gml:Y>58.961058642578</gml:Y></gml:coord>
   </BoundingBox>
   <Output>
      <Format>image/png</Format>
      <Size><Width>780</Width><Height>330</Height></Size>
   </Output>
</ogc:GetMap>

However, when I try to execute a similar curl command with a different GetMap XML file (now including a native query), it does not work, I mean, it returns the same image as without applying the filter {“term”:{“country”:“Spain”}}, the filter is not taken into account:

curl -X POST -H "Content-Type:text/xml" --data @getMap2.xml "http://localhost:8080/geoserver/wms?request=GetMap&service=WMS&version=1.1.1&styles=&srs=EPSG%3A4326" -o output_image.png

The content of getMap2.xml is as follows, which includes a native query as I have understood from the documentation:

<?xml version="1.0" encoding="UTF-8"?>
<ogc:GetMap xmlns:ogc="http://www.opengis.net/ows"
            xmlns:gml="http://www.opengis.net/gml"
            version="1.1.1" service="WMS">
   <StyledLayerDescriptor version="1.0.0">
      <NamedLayer>
        <Name>mytest:mytest</Name>
      </NamedLayer>
      <UserStyle>
        <Title>Test</Title>
        <Abstract>Test Native Query</Abstract>
        <FeatureTypeStyle>
          <Transformation>
            <ogc:Function name="vec:GeoHashGrid">
              <ogc:Function name="parameter">
                <ogc:Literal>data</ogc:Literal>
              </ogc:Function>
              <ogc:Function name="parameter">
                <ogc:Literal>queryDefinition</ogc:Literal>
                <ogc:Literal>{"term":{"country":"Spain"}}</ogc:Literal>
              </ogc:Function>
            </ogc:Function>
          </Transformation>
        </FeatureTypeStyle>
      </UserStyle>
   </StyledLayerDescriptor>
   <BoundingBox srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
      <gml:coord><gml:X>-145.15104058007</gml:X><gml:Y>21.731919794922</gml:Y></gml:coord>
      <gml:coord><gml:X>-57.154894212888</gml:X><gml:Y>58.961058642578</gml:coord>
   </BoundingBox>
   <Output>
      <Format>image/png</Format>
      <Size><Width>780</Width><Height>330</Height></Size>
   </Output>
</ogc:GetMap>

Hi,
It would be easier to help you if you give some more information about what happens. You just say that it doesn’t work. I suppose you get some kind of response. You could also look in the log files of Geoserver for some clues of what goes wrong.

Best regards,
Roar Brænden

Hi, Roar
After posting, I realized that information was precisely missing. I couldn’t edit it at that moment because it was my first question in this forum and it had to be approved by the administrators. I have now edited the question by adding that it returns the same image without applying the filter {“term”:{“country”:“Spain”}}.

Hi,

I have no knowledge of this module, but it seems like you’re trying for something else than the example. You are posting the StyledLayerDescriptor as part of the wms request, while in the example the StyledLayerDescriptor-xml is supposed to be stored in Geoserver as the definition of the style NativeQueryStyle.

Another issue that might cause trouble is that your Transformation is lacking the parameters outputBBox, outputWidth and outputHeight.

Best regards,
Roar Brænden