-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Fix/geoshape #788
Fix/geoshape #788
Conversation
Hey @gmarz Some initial thoughts: Im not totally sold on the I think the simpler solution would be to simplify it to: public interface IGeoShape
{
[JsonProperty("type")]
string Type { get; set; }
} Then each individual shape is free to define Then the new contract will be For this to work the interface will need to be added to the list in |
@Mpdreamz So that is the exact route I initially went down, and it works as expected except for one issue: With the new object initializer syntax, we want to be able to deserialize any string into a NEST query object (https://github.com/elasticsearch/elasticsearch-net/tree/develop/src/Tests/Nest.Tests.Unit/QueryParsers). With just an IGeoShape object as part of the request, that only has a Type property, Coordinates and Radius are both lost after deserializing, because it only knows about IGeoShape, thus failing https://github.com/elasticsearch/elasticsearch-net/blob/develop/src/Tests/Nest.Tests.Unit/QueryParsers/Queries/GeoShapeQueryTests.cs. Otherwise, that would be the preferred solution. What do you think? |
We might need specialized sub interfaces of In combination with a custom deserializer. Or we give up and simplify the interface to include coordinates and radius always. |
… the specialized geoshape writer but written using the mode generic fieldname converter
@Mpdreamz the IGeoShape and sub-interfaces approach you suggested worked like a charm. This PR is complete now and ready to be merged. Fluent example:
Object initializer example:
|
Conflicts: src/Nest/DSL/Filter/GeoShapeFilterDescriptor.cs src/Nest/Domain/DSL/GeoShapeVector.cs src/Nest/Nest.csproj
This PR addresses issues two issues (#776 and #782) with the current geo shape support in NEST. Previously, NEST only allowed for a Coordinates object of type IEnumerable<IEnumerable> for shapes which only worked for a sub set of the GeoJSON objects that Elasticsearch supports.
GeoShape descriptors now expose a Shape() method rather than Type() and Coordinates(), which accepts an IGeometryObject. All of the supported GeoJSON objects can be found in Nest/Domain/Geometry and all inherit from a base GeometryObject which implements IGeometryObject.
Instead of this:
One can now do this:
Which automatically sets the geo shape type as well. There is no longer a need to call Type() to specifiy it separately anymore.
When using the OIS, ToGeoShape() has to explicitly be called, whereas the descriptors call it automatically when Shape is set:
Not very ideal, open to suggestions here. The reason for this is that the GeoShape object that's part of the request needs to be generic enough to account for all the different geo shape parameters ES takes. Right now, the main differences are the different Coordinate types (which is why Coordinates is of type object), and Radius which only applies when using the Circle shape.
Check out the tests here to see an example usage of all the shapes: https://github.com/elasticsearch/elasticsearch-net/tree/fix/geoshape/src/Tests/Nest.Tests.Unit/Search/Query/Singles/GeoShape
NOTE: This introduces a breaking change between RC1.0 to GA, but one worth having. We could put back the Type() and Coordinates() methods and just let Shape() override them, but it may be confusing.