Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for (alternative for) GeoShapeQuery #8169

Open
arthurvb opened this issue Apr 25, 2024 · 2 comments
Open

Support for (alternative for) GeoShapeQuery #8169

arthurvb opened this issue Apr 25, 2024 · 2 comments
Labels
8.x Relates to 8.x client version Area: Generator Category: Feature

Comments

@arthurvb
Copy link

Is your feature request related to a problem? Please describe.
We want to port our (Nest) Elastic API to the v8. Currently we use the GeoShapeQuery , mapping to https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-shape-query.html . However it seems that in the latest version we cannot create this query type.

Describe the solution you'd like
A way to create GeoShapeQuery's in the latest C# Elastic Client API

Describe alternatives you've considered
Looking at bounding boxes, geopolygon queries, but they all have different semantics

Additional context
Many thanks in advance!

@flobernd flobernd added 8.x Relates to 8.x client version Area: Generator labels Apr 25, 2024
@flobernd
Copy link
Member

Hi @arthurvb, the GeoShapeQuery indeed is one of the few things missing right now. It's definitely planned to bring back support for this, but in the meantime there is no workaround 🙁 (except for completely hand-crafting the query using the low-level client).

@Genide
Copy link

Genide commented May 8, 2024

For those also stumble across this problem, this cannot be accomplished with QueryDescriptor<>.RawJson and RawJsonQuery.

The RawJsonQuery description says the following.

Allows a query represented as a string of JSON to be defined. This can be useful when support for a built-in query is not yet available.

However, the behavior I see is different from what I expected. I tried the following code snippet.

        // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-shape-query.html
        var filter = new
        {
            geo_shape = new
            {
                location = new
                {
                    shape = geometryCollection,
                    relation = "within"
                }
            }
        };
        var queryString = JsonSerializer.Serialize(filter);

        var result = await _client.SearchAsync<Prospect>(s => s
            .Query(q => q.RawJson(new RawJsonQuery(queryString))) // Line of code in question
            // .Query(new RawJsonQuery(queryString))) An alternative way, but same result
        );

Current Behavior

However the generated query was the following.

{
  "query": {
    "raw_json": { // The "raw_json" query type does not exist. I'm pretty sure this is not intended behavior.
      "geo_shape": {
        "location": {
          "shape": {
            "type": "GeometryCollection",
            "geometries": [
              {
                "type": "MultiPolygon",
                "coordinates": [
                  // skip for brevity
                ]
              }
            ]
          },
          "relation": "within"
        }
      }
    }
  }
}

Expected Behavior

{
  "query": {
    "geo_shape": {
      "location": {
        "shape": {
          "type": "GeometryCollection",
          "geometries": [
            {
              "type": "MultiPolygon",
              "coordinates": [
                // skip for brevity
              ]
            }
          ]
        },
        "relation": "within"
      }
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8.x Relates to 8.x client version Area: Generator Category: Feature
Projects
None yet
Development

No branches or pull requests

3 participants