- .NET Clients: other versions:
- Introduction
- Installation
- Breaking changes
- API Conventions
- Elasticsearch.Net - Low level client
- NEST - High level client
- Troubleshooting
- Search
- Query DSL
- Full text queries
- Term level queries
- Exists Query Usage
- Fuzzy Date Query Usage
- Fuzzy Numeric Query Usage
- Fuzzy Query Usage
- Ids Query Usage
- Prefix Query Usage
- Date Range Query Usage
- Long Range Query Usage
- Numeric Range Query Usage
- Term Range Query Usage
- Regexp Query Usage
- Term Query Usage
- Terms Set Query Usage
- Terms List Query Usage
- Terms Lookup Query Usage
- Terms Query Usage
- Wildcard Query Usage
- Compound queries
- Joining queries
- Geo queries
- Specialized queries
- Span queries
- NEST specific queries
- Aggregations
- Metric Aggregations
- Average Aggregation Usage
- Boxplot Aggregation Usage
- Cardinality Aggregation Usage
- Extended Stats Aggregation Usage
- Geo Bounds Aggregation Usage
- Geo Centroid Aggregation Usage
- Geo Line Aggregation Usage
- Max Aggregation Usage
- Median Absolute Deviation Aggregation Usage
- Min Aggregation Usage
- Percentile Ranks Aggregation Usage
- Percentiles Aggregation Usage
- Rate Aggregation Usage
- Scripted Metric Aggregation Usage
- Stats Aggregation Usage
- String Stats Aggregation Usage
- Sum Aggregation Usage
- T Test Aggregation Usage
- Top Hits Aggregation Usage
- Top Metrics Aggregation Usage
- Value Count Aggregation Usage
- Weighted Average Aggregation Usage
- Bucket Aggregations
- Adjacency Matrix Usage
- Auto Date Histogram Aggregation Usage
- Children Aggregation Usage
- Composite Aggregation Usage
- Date Histogram Aggregation Usage
- Date Range Aggregation Usage
- Diversified Sampler Aggregation Usage
- Filter Aggregation Usage
- Filters Aggregation Usage
- Geo Distance Aggregation Usage
- Geo Hash Grid Aggregation Usage
- Geo Tile Grid Aggregation Usage
- Global Aggregation Usage
- Histogram Aggregation Usage
- Ip Range Aggregation Usage
- Missing Aggregation Usage
- Multi Terms Aggregation Usage
- Nested Aggregation Usage
- Parent Aggregation Usage
- Range Aggregation Usage
- Rare Terms Aggregation Usage
- Reverse Nested Aggregation Usage
- Sampler Aggregation Usage
- Significant Terms Aggregation Usage
- Significant Text Aggregation Usage
- Terms Aggregation Usage
- Variable Width Histogram Usage
- Pipeline Aggregations
- Average Bucket Aggregation Usage
- Bucket Script Aggregation Usage
- Bucket Selector Aggregation Usage
- Bucket Sort Aggregation Usage
- Cumulative Cardinality Aggregation Usage
- Cumulative Sum Aggregation Usage
- Derivative Aggregation Usage
- Extended Stats Bucket Aggregation Usage
- Max Bucket Aggregation Usage
- Min Bucket Aggregation Usage
- Moving Average Ewma Aggregation Usage
- Moving Average Holt Linear Aggregation Usage
- Moving Average Holt Winters Aggregation Usage
- Moving Average Linear Aggregation Usage
- Moving Average Simple Aggregation Usage
- Moving Function Aggregation Usage
- Moving Percentiles Aggregation Usage
- Normalize Aggregation Usage
- Percentiles Bucket Aggregation Usage
- Serial Differencing Aggregation Usage
- Stats Bucket Aggregation Usage
- Sum Bucket Aggregation Usage
- Matrix Aggregations
- Metric Aggregations
Shape Query Usage
editShape Query Usage
editLike geo_shape, Elasticsearch supports the ability to index arbitrary two dimension (non Geospatial) geometries making it possible to map out virtual worlds, sporting venues, theme parks, and CAD diagrams. The shape field type supports points, lines, polygons, multi-polygons, envelope, etc.
See the Elasticsearch documentation on shape queries for more detail.
Querying with Point
editFluent DSL example
editq .Shape(c => c .Name("named_query") .Boost(1.1) .Field(p => p.ArbitraryShape) .Shape(s => s .Point(PointCoordinates) ) .Relation(ShapeRelation.Intersects) )
Object Initializer syntax example
editnew ShapeQuery { Name = "named_query", Boost = 1.1, Field = Infer.Field<Project>(p => p.ArbitraryShape), Shape = new PointGeoShape(PointCoordinates), Relation = ShapeRelation.Intersects }
Example json output.
{ "shape": { "_name": "named_query", "boost": 1.1, "arbitraryShape": { "relation": "intersects", "shape": { "type": "point", "coordinates": [ 38.897676, -77.03653 ] } } } }
Querying with MultiPoint
editElasticsearch 7.7.0+ required when MultiPoint is indexed using BKD trees (the default).
Fluent DSL example
editq .Shape(c => c .Name("named_query") .Boost(1.1) .Field(p => p.ArbitraryShape) .Shape(s => s .MultiPoint(MultiPointCoordinates) ) .Relation(ShapeRelation.Intersects) )
Object Initializer syntax example
editnew ShapeQuery { Name = "named_query", Boost = 1.1, Field = Infer.Field<Project>(p => p.ArbitraryShape), Shape = new MultiPointGeoShape(MultiPointCoordinates), Relation = ShapeRelation.Intersects, }
Example json output.
{ "shape": { "_name": "named_query", "boost": 1.1, "arbitraryShape": { "relation": "intersects", "shape": { "type": "multipoint", "coordinates": [ [ 38.897676, -77.03653 ], [ 38.889939, -77.009051 ] ] } } } }
Querying with LineString
editFluent DSL example
editq .Shape(c => c .Name("named_query") .Boost(1.1) .Field(p => p.ArbitraryShape) .Shape(s => s .LineString(LineStringCoordinates) ) .Relation(ShapeRelation.Intersects) )
Object Initializer syntax example
editnew ShapeQuery { Name = "named_query", Boost = 1.1, Field = Infer.Field<Project>(p => p.ArbitraryShape), Shape = new LineStringGeoShape(LineStringCoordinates), Relation = ShapeRelation.Intersects, }
Example json output.
{ "shape": { "_name": "named_query", "boost": 1.1, "arbitraryShape": { "relation": "intersects", "shape": { "type": "linestring", "coordinates": [ [ 38.897676, -77.03653 ], [ 38.889939, -77.009051 ] ] } } } }
Querying with MultiLineString
editFluent DSL example
editq .Shape(c => c .Name("named_query") .Boost(1.1) .Field(p => p.ArbitraryShape) .Shape(s => s .MultiLineString(MultiLineStringCoordinates) ) .Relation(ShapeRelation.Intersects) )
Object Initializer syntax example
editnew ShapeQuery { Name = "named_query", Boost = 1.1, Field = Infer.Field<Project>(p => p.ArbitraryShape), Shape = new MultiLineStringGeoShape(MultiLineStringCoordinates), Relation = ShapeRelation.Intersects, }
Example json output.
{ "shape": { "_name": "named_query", "boost": 1.1, "arbitraryShape": { "relation": "intersects", "shape": { "type": "multilinestring", "coordinates": [ [ [ 2.0, 12.0 ], [ 2.0, 13.0 ], [ 3.0, 13.0 ], [ 3.0, 12.0 ] ], [ [ 0.0, 10.0 ], [ 0.0, 11.0 ], [ 1.0, 11.0 ], [ 1.0, 10.0 ] ], [ [ 0.2, 10.2 ], [ 0.2, 10.8 ], [ 0.8, 10.8 ], [ 0.8, 12.0 ] ] ] } } } }
Querying with Polygon
editFluent DSL example
editq .Shape(c => c .Name("named_query") .Boost(1.1) .Field(p => p.ArbitraryShape) .Shape(s => s .Polygon(PolygonCoordinates) ) .IgnoreUnmapped() .Relation(ShapeRelation.Intersects) )
Object Initializer syntax example
editnew ShapeQuery { Name = "named_query", Boost = 1.1, Field = Infer.Field<Project>(p => p.ArbitraryShape), Shape = new PolygonGeoShape(PolygonCoordinates), IgnoreUnmapped = true, Relation = ShapeRelation.Intersects, }
Example json output.
{ "shape": { "_name": "named_query", "boost": 1.1, "ignore_unmapped": true, "arbitraryShape": { "relation": "intersects", "shape": { "type": "polygon", "coordinates": [ [ [ 10.0, -17.0 ], [ 15.0, 16.0 ], [ 0.0, 12.0 ], [ -15.0, 16.0 ], [ -10.0, -17.0 ], [ 10.0, -17.0 ] ], [ [ 8.2, 18.2 ], [ 8.2, -18.8 ], [ -8.8, -10.8 ], [ 8.8, 18.2 ] ] ] } } } }
Querying with MultiPolygon
editFluent DSL example
editq .Shape(c => c .Name("named_query") .Boost(1.1) .Field(p => p.ArbitraryShape) .Shape(s => s .MultiPolygon(MultiPolygonCoordinates) ) .Relation(ShapeRelation.Intersects) )
Object Initializer syntax example
editnew ShapeQuery { Name = "named_query", Boost = 1.1, Field = Infer.Field<Project>(p => p.ArbitraryShape), Shape = new MultiPolygonGeoShape(MultiPolygonCoordinates), Relation = ShapeRelation.Intersects, }
Example json output.
{ "shape": { "_name": "named_query", "boost": 1.1, "arbitraryShape": { "relation": "intersects", "shape": { "type": "multipolygon", "coordinates": [ [ [ [ 10.0, -17.0 ], [ 15.0, 16.0 ], [ 0.0, 12.0 ], [ -15.0, 16.0 ], [ -10.0, -17.0 ], [ 10.0, -17.0 ] ], [ [ 8.2, 18.2 ], [ 8.2, -18.8 ], [ -8.8, -10.8 ], [ 8.8, 18.2 ] ] ], [ [ [ 8.0, -15.0 ], [ 15.0, 16.0 ], [ 0.0, 12.0 ], [ -15.0, 16.0 ], [ -10.0, -17.0 ], [ 8.0, -15.0 ] ] ] ] } } } }
Querying with GeometryCollection
editFluent DSL example
editq .Shape(c => c .Name("named_query") .Boost(1.1) .Field(p => p.ArbitraryShape) .Shape(s => s .GeometryCollection( new PointGeoShape(PointCoordinates), new MultiPointGeoShape(MultiPointCoordinates), new LineStringGeoShape(LineStringCoordinates), new MultiLineStringGeoShape(MultiLineStringCoordinates), new PolygonGeoShape(PolygonCoordinates), new MultiPolygonGeoShape(MultiPolygonCoordinates) ) ) .Relation(ShapeRelation.Intersects) )
Object Initializer syntax example
editnew ShapeQuery { Name = "named_query", Boost = 1.1, Field = Infer.Field<Project>(p => p.ArbitraryShape), Shape = new GeometryCollection(new IGeoShape[] { new PointGeoShape(PointCoordinates), new MultiPointGeoShape(MultiPointCoordinates), new LineStringGeoShape(LineStringCoordinates), new MultiLineStringGeoShape(MultiLineStringCoordinates), new PolygonGeoShape(PolygonCoordinates), new MultiPolygonGeoShape(MultiPolygonCoordinates), }), Relation = ShapeRelation.Intersects, }
Example json output.
{ "shape": { "_name": "named_query", "boost": 1.1, "arbitraryShape": { "relation": "intersects", "shape": { "type": "geometrycollection", "geometries": [ { "type": "point", "coordinates": [ 38.897676, -77.03653 ] }, { "type": "multipoint", "coordinates": [ [ 38.897676, -77.03653 ], [ 38.889939, -77.009051 ] ] }, { "type": "linestring", "coordinates": [ [ 38.897676, -77.03653 ], [ 38.889939, -77.009051 ] ] }, { "type": "multilinestring", "coordinates": [ [ [ 2.0, 12.0 ], [ 2.0, 13.0 ], [ 3.0, 13.0 ], [ 3.0, 12.0 ] ], [ [ 0.0, 10.0 ], [ 0.0, 11.0 ], [ 1.0, 11.0 ], [ 1.0, 10.0 ] ], [ [ 0.2, 10.2 ], [ 0.2, 10.8 ], [ 0.8, 10.8 ], [ 0.8, 12.0 ] ] ] }, { "type": "polygon", "coordinates": [ [ [ 10.0, -17.0 ], [ 15.0, 16.0 ], [ 0.0, 12.0 ], [ -15.0, 16.0 ], [ -10.0, -17.0 ], [ 10.0, -17.0 ] ], [ [ 8.2, 18.2 ], [ 8.2, -18.8 ], [ -8.8, -10.8 ], [ 8.8, 18.2 ] ] ] }, { "type": "multipolygon", "coordinates": [ [ [ [ 10.0, -17.0 ], [ 15.0, 16.0 ], [ 0.0, 12.0 ], [ -15.0, 16.0 ], [ -10.0, -17.0 ], [ 10.0, -17.0 ] ], [ [ 8.2, 18.2 ], [ 8.2, -18.8 ], [ -8.8, -10.8 ], [ 8.8, 18.2 ] ] ], [ [ [ 8.0, -15.0 ], [ 15.0, 16.0 ], [ 0.0, 12.0 ], [ -15.0, 16.0 ], [ -10.0, -17.0 ], [ 8.0, -15.0 ] ] ] ] } ] } } } }
Querying with Envelope
editFluent DSL example
editq .Shape(c => c .Name("named_query") .Boost(1.1) .Field(p => p.ArbitraryShape) .Shape(s => s .Envelope(EnvelopeCoordinates) ) .Relation(ShapeRelation.Intersects) )
Object Initializer syntax example
editnew ShapeQuery { Name = "named_query", Boost = 1.1, Field = Infer.Field<Project>(p => p.ArbitraryShape), Shape = new EnvelopeGeoShape(EnvelopeCoordinates), Relation = ShapeRelation.Intersects, }
Example json output.
{ "shape": { "_name": "named_query", "boost": 1.1, "arbitraryShape": { "relation": "intersects", "shape": { "type": "envelope", "coordinates": [ [ -45.0, 45.0 ], [ 45.0, -45.0 ] ] } } } }
Querying with Circle
editAvailable in Elasticsearch 7.7.0+
Fluent DSL example
editq .Shape(c => c .Name("named_query") .Boost(1.1) .Field(p => p.ArbitraryShape) .Shape(s => s .Circle(CircleCoordinates, "100m") ) .Relation(ShapeRelation.Intersects) )
Object Initializer syntax example
editnew ShapeQuery { Name = "named_query", Boost = 1.1, Field = Infer.Field<Project>(p => p.ArbitraryShape), Shape = new CircleGeoShape(CircleCoordinates, "100m"), Relation = ShapeRelation.Intersects, }
Example json output.
{ "shape": { "_name": "named_query", "boost": 1.1, "arbitraryShape": { "relation": "intersects", "shape": { "type": "circle", "radius": "100m", "coordinates": [ 45.0, -45.0 ] } } } }
Querying with an indexed shape
editThe Query also supports using a shape which has already been indexed in another index. This is particularly useful for when you have a pre-defined list of shapes which are useful to your application and you want to reference this using a logical name (for example New Zealand) rather than having to provide their coordinates each time. In this situation it is only necessary to provide:
See the Elasticsearch documentation on https://www.elastic.co/guide/en/elasticsearch/reference/7.17/query-dsl-shape-query.html for more detail.
Fluent DSL example
editq .Shape(c => c .Name("named_query") .Boost(1.1) .Field(p => p.ArbitraryShape) .IndexedShape(p => p .Id(Project.Instance.Name) .Path(pp => pp.ArbitraryShape) .Routing(Project.Instance.Name) ) .Relation(ShapeRelation.Intersects) )
Object Initializer syntax example
editnew ShapeQuery { Name = "named_query", Boost = 1.1, Field = Infer.Field<Project>(p => p.ArbitraryShape), IndexedShape = new FieldLookup { Id = Project.Instance.Name, Index = Infer.Index<Project>(), Path = Infer.Field<Project>(p => p.ArbitraryShape), Routing = Project.Instance.Name }, Relation = ShapeRelation.Intersects }
Example json output.
{ "shape": { "_name": "named_query", "boost": 1.1, "arbitraryShape": { "indexed_shape": { "id": "Durgan LLC", "index": "project", "path": "arbitraryShape", "routing": "Durgan LLC" }, "relation": "intersects" } } }
On this page
- Querying with Point
- Fluent DSL example
- Object Initializer syntax example
- Querying with MultiPoint
- Fluent DSL example
- Object Initializer syntax example
- Querying with LineString
- Fluent DSL example
- Object Initializer syntax example
- Querying with MultiLineString
- Fluent DSL example
- Object Initializer syntax example
- Querying with Polygon
- Fluent DSL example
- Object Initializer syntax example
- Querying with MultiPolygon
- Fluent DSL example
- Object Initializer syntax example
- Querying with GeometryCollection
- Fluent DSL example
- Object Initializer syntax example
- Querying with Envelope
- Fluent DSL example
- Object Initializer syntax example
- Querying with Circle
- Fluent DSL example
- Object Initializer syntax example
- Querying with an indexed shape
- Fluent DSL example
- Object Initializer syntax example