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

Probably a bug in GeoShape filter #776

Closed
mikeerrecart opened this issue Jul 10, 2014 · 6 comments
Closed

Probably a bug in GeoShape filter #776

mikeerrecart opened this issue Jul 10, 2014 · 6 comments
Assignees
Milestone

Comments

@mikeerrecart
Copy link

Hi, Not sure where the bug lies but here's what i came into.
The following code (a GeoShape filtered query) :

List<List<double>> gs_polygone_quiberon = new List<List<double>>() { 
                new List<double>() {-3.183515, 47.542491} 
                , new List<double>(){-3.095624, 47.537624} 
                , new List<double>(){-3.026788, 47.478487}
                , new List<double>() {-3.190896, 47.452956}
                , new List<double>() {-3.183515, 47.542491} 
            };

var results = client
    .Search<Elastic_Oi>(s =>
        s
        .AllIndices()
        .From(0)
        .AllTypes()
        .Size(10)
        .Query(q => q.Filtered(
                    f => f.Filter(x =>
                        x.GeoShape("GeoShapeLocation", d => d.Type("polygon").Coordinates(gs_polygone_quiberon))
                        )
                    )
        )
    );

generates the following JSon :

{
  "from": 0,
  "size": 10,
  "query": {
    "filtered": {
      "filter": {
        "geo_shape": {
          "GeoShapeLocation": {
            "shape": {
              "type": "polygon",
              "coordinates": [
                [
                  -3.183515,
                  47.542491
                ],
                [
                  -3.095624,
                  47.537624
                ],
                [
                  -3.026788,
                  47.478487
                ],
                [
                  -3.190896,
                  47.452956
                ],
                [
                  -3.183515,
                  47.542491
                ]
              ]
            }
          }
        }
      }
    }
  }
}

and an 400 error in NEST.

Executing the Json directly in ES generates a null pointer exception. To be able to execute the query i have to add an indentation level in the "coordinates" field like in the following Json (i wrapped all the "coordinates" field value in []

{
  "from": 0,
  "size": 10,
  "query": {
    "filtered": {
      "filter": {
        "geo_shape": {
          "GeoShapeLocation": {
            "shape": {
              "type": "polygon",
              "coordinates": [[
                [
                  -3.183515,
                  47.542491
                ],
                [
                  -3.095624,
                  47.537624
                ],
                [
                  -3.026788,
                  47.478487
                ],
                [
                  -3.190896,
                  47.452956
                ],
                [
                  -3.183515,
                  47.542491
                ]
              ]]
            }
          }
        }
      }
    }
  }
}

This query works like a charm, but is impossible to reproduce using Nest, the Coordinates method of the GeoShape filter takes a IEnumerable<IEnumerable<double>> parameter, not a IEnumerable<IEnumerable<IEnumerable<double>>> parameter.

Is the bug in Nest ? My code ? ES ?

Thanks in advance !

Mike

@gmarz
Copy link
Contributor

gmarz commented Jul 11, 2014

Hey @mikeerrecart, I'm looking into this. Would you mind posting your mapping, version of NEST, and version of ES?

@mikeerrecart
Copy link
Author

Hey @gmarz, no problem. I'm using NEST 1.0.0.beta1 and ES 1.2.1

Here's the relevant part (GeoShapeLocation field) of the mapping (the entire mapping is quite big)

{
        "properties": {

            "Description": {
                "type": "string",
                "index": "analyzed",
                "analyzer" : "french"
            },
            "GeoShapeLocation" : {
                "type" : "geo_shape",
                "tree": "quadtree",
                "precision": "1m"
            }
        }
}

@gmarz
Copy link
Contributor

gmarz commented Jul 11, 2014

@mikeerrecart So the issue here is indeed with NEST.

Take a look at http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-geo-shape-type.html. Coordinates are structured differently depending on the type (i.e. linestring vs polygon). Some take an array, some take an array of arrays, others take an array of array of arrays, etc...

As you've discovered, NEST right now only supports the array of array case, which only covers linestring, multipoint, and envelope.

We'll work on a fix for this and will keep you posted. Great catch- thank you for finding this.

@mikeerrecart
Copy link
Author

@gmarz Thanks, i'll wait for the fix.

@gmarz gmarz self-assigned this Jul 13, 2014
@Mpdreamz Mpdreamz added this to the NEST 1.0 milestone Jul 16, 2014
@gmarz
Copy link
Contributor

gmarz commented Jul 16, 2014

@mikeerrecart this is fixed now. The API has changed a bit and now accounts for all the different shapes that ES supports.

Here's how you would execute your above example with the new API:

var results = client
    .Search<Elastic_Oi>(s => s
        .AllIndices()
        .From(0)
        .AllTypes()
        .Size(10)
        .Query(q => q.Filtered(
            f => f.Filter(x =>
                    x.GeoShapePolygon("GeoShapeLocation", d => d.Coordinates(gs_polygone_quiberon))
                )
            )
        )
    );

For full examples of both geoshape queries and filters, take a look at the following tests:

https://github.com/elasticsearch/elasticsearch-net/blob/develop/src/Tests/Nest.Tests.Unit/Search/Filter/Singles/GeoShapeFilterJson.cs

https://github.com/elasticsearch/elasticsearch-net/tree/develop/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape

@gmarz gmarz closed this as completed Jul 16, 2014
@mikeerrecart
Copy link
Author

@gmarz Thanks so much. I'm waitin gfor the nuget package now ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants