Two data types: geo_point and geo_shape: geographic location type, latitude and longitude coordinates

geo_point

Latitude and longitude coordinates, only WGS84 coordinate system is supported, the coordinate range Lat value is [-90,90], Lon is [-180,180]

  • Latitude: latitude: lAT
  • It’s longitude. It’s lon
  • Ignore_malformed: ignores the geographical location of the formatting error. If false (default)
  • Five types of storage
# mapping PUT geo_point {"mappings": {"properties": {"name": {"type": "text"}, "location": {"type": {"name": {"type": "text"}, "location": {"type": { "Geo_point"}}}} # first PUT geo_point _doc / 1 {" name ":" tiananmen square ", "location" : {" lat ": 40.12," says lon ": -71.34}} #"lat,lon" PUT geo_point/_doc/2 {"name": "front door ", "location": "40.12, 72.34} # [lon, lat] the third PUT geo_point _doc / 3 {" name" : "back door", "location" : [75.34, 40.12]} # WKT PUT geo_point _doc / 2 {" name ":" the front ", "location" : "POINT (72.34, 40.12)"} # # GEO hash GEO hash https://www.cnblogs.com/LBSer/p/3310455.html GET/geo_point / _mapping GET /geo_point/_searchCopy the code

geo_shape

One of the special types of ES, used to describe the types of complex geometric figures, such as points, lines, planes, polygons and other two-dimensional geometric models.

  • GeoJSON: GeoJSON is a format for encoding a variety of geographic data structures, supporting the following geometric types:
    • Point: a Point
    • LineString: line
    • Polygon: Polygon
    • MultiPoint: a MultiPoint
    • MultiLineString: multiple line segments
    • MultiPolygon: collection of polygons
    • Feature: Object with other attributes
  • WKT (well-known Text) : POINT(125.6 10.1)
DELETE geo_shape GET geo_shape/_mapping PUT geo_shape { "mappings": { "properties": { "location": { "type": "Geo_shape"}}}} # store one POST/geo_shape / _doc / 1 {" name ":" Chinese sweet sea ", "location" : {" type ":" point ", Coordinates "coordinates":[13.400544, 52.530286]}} #WKT GET geo_shape/_doc/1 POST /geo_shape/_doc/1 {"coordinates":[13.400544, 52.530286]}} #WKT GET geo_shape/_doc/1 POST /geo_shape/_doc/1 {"coordinates": "Location ":"POINT (13.400544 52.530286)"} # POST /geo_shape/_doc/2 { "Location" : {" type ":" linestring, "" coordinates" : [[13.400544, 52.530286], [77.400544, }} # POST /geo_shape/_doc/2 {"name": } # Store a geometry POST /geo_shape/_doc/3 {"name": "Coordinates ": {"type": "polygon", "coordinates": [[[100, 0], [101, 0], [101, 1], [100, 1], [100, 0]], [[100.2, 0.2], [100.8, 0.2], [100.8, 0.8]. [100.2, 0.8], [100.2, 0.2]]}} # POST /geo_shape/_doc/3 {"location" : "POLYGON ((100.0 0.0, 101.0 0.0, 101.0 1.0, 100.0 1.0, 100.0, 0.0)) "} PUT _ingest/pipeline/polygonize_circles {" description ":" the circle into a polygon ", "processors" : [{" circle ": { "field": "location", "error_distance": 0, "shape_type": "geo_shape" } } ] } POST /geo_shape/_doc/4? Pipeline = Polygonize_circles {"name": "safe zone ", "location": {"type": "circle", "coordinates": [30.0, 10.0], "radius":"1m"}}Copy the code

Four types of queries

Geo_bounding box Query

In the same plane, two points determine a rectangle and search the coordinate parameters in the rectangle:

  • Top_left: coordinates of the upper left point of the rectangle
  • Bottom_right: indicates the table at the upper right corner of the rectangle
#geo_bounding box query GET /geo_point/_search { "query": { "geo_bounding_box":{ "location":{ "top_left":{ "lat": 50.73, "says lon" : 74.1}, "bottom_right" : {" lat ": 30.01," says lon ": 61.12}}}}}Copy the code

Geo_distance query

Finds the coordinates of a circle with a specified radius centered at a point.

  • Distance: the unit of distance, which defaults to meters, supports the following options
    • “Mile” : mi or miles
    • Yard: yd or yards
    • Feet: ft or Feet
    • Inch: in or Inch
    • Kilometer (km) : kilometers or kilometers
    • Meter(米):m后者meters
    • Rectification: cm or centimeters
    • Millimetres: millimeters or millimeters
    • Nautical Mile (Nautical mile) : NM, NMI, or Nautical Miles
  • Distance_type: method of calculating distance
    • Arc (default) : More accurate, but slower
    • Plane :(faster, but not accurate over long distances and near poles)
GET /geo_point/_search {"query": {"bool": {"filter": [{"geo_distance": {"distance": "500km", "location": { "lat": 40, "lon": -71 } } } ] } } }Copy the code

Geo_polygon query

Find the coordinates of a polygon formed by a given number of points. A closed polygon whose first and last points must match requires n + 1 vertices to create a polygon with n-sides and a minimum of 4 vertices.

# polygon to find GET geo_point / _search {" query ": {" bool" : {" must ": [{" match_all" : {}}], "filter" : [{" geo_polygon ": { "location": { "points": [ { "lat": 40, "lon": -170 }, { "lat": 40, "lon": -171 }, { "lat": 50, "lon": 171.1}, {" lat ": 40," says lon ": 170}]]}}}}}}Copy the code

Geo_shape Query (special geometry)

Supports graph retrieval of intersecting, including or disintersecting specified geometric figures

  • Inline Shape Definition: the Shape envelope defined by the Inline Shape itself, namely: box
GET geo_shape/_search
{
  "query": {
    "bool": {
      "filter": [
        {
          "geo_shape": {
            "location": {
              "shape": {
                "type": "envelope",
                "coordinates": [
                  [
                    13,
                    53
                  ],
                  [
                    14,
                    52
                  ]
                ]
              },
              "relation": "within"
            }
          }
        }
      ]
    }
  }
}
Copy the code
  • Pre-Indexed Shape

Use the existing data, query the data in the data, such as: query the tourist attractions in Henan Province

  • Id – The document ID that contains the pre-indexed shape.
  • Index – The name of the index, where the pre-index shape is the default shape.
  • Routing-optional.
  • Path – Specifies the path containing the pre-indexed shape, the default shape.
GET /geo_shape/_search
{
  "query": {
    "bool": {
      "filter": {
        "geo_shape": {
          "location": {
            "indexed_shape": {
              "index": "geo_shape",
              "id": "4",
              "path": "location"
            },
            "relation": "within"
          }
        }
      }
    }
  }
}
Copy the code

Spatial Relations

  • INTERSECTS- (default) returns all documents whose geo_shape field INTERSECTS the query geometry.
  • DISJOINT- Returns all documents whose geo_SHAPE field has nothing in common with the query geometry.
  • WITHIN- Returns all documents whose geo_SHAPE field is in the query geometry.
  • CONTAINS- Returns all documents whose geo_SHAPE field CONTAINS the query geometry.

PUT geo_shape_test { "mappings": { "properties": { "location": { "type": POST /geo_shape_test/_doc/A {"location": {"type": "envelope", "coordinates": [[1, 7], [6, 1]] POST/geo_shape_test / _doc / {B}} "location" : {" type ":" envelope ", "coordinates" : [[4, 8], [8, 5]] {}} POST/geo_shape_test _doc/C "location" : {" type ":" envelope ", "coordinates" : [[2, 4], [4, 2]]}} # P1 POST/geo_shape_test _doc/P1 {" name ":" P1 ", "location" : {" type ":" point ", "coordinates" : [3, 3] } } #P2 POST /geo_shape_test/_doc/P2 { "name":"P2", "location":{ "type":"point", "coordinates":[5, 6] } } #P3 POST /geo_shape_test/_doc/P3 { "name":"P3", "location":{ "type":"point", "coordinates":[7, 7] } } #P4 POST /geo_shape_test/_doc/P4 { "name":"P4", "location":{ "type":"point", "coordinates":[3, 5] } } #P5 POST /geo_shape_test/_doc/P5 { "name":"P5", "location":{ "type":"point", "coordinates":[7, 3] } } GET /geo_shape_test/_search { "query": { "bool": { "filter": { "geo_shape": { "location": { "indexed_shape": { "index": "geo_shape_test", "id": "A", "path": "location" }, "relation": "intersects" } } } } } }Copy the code

The precision of the polygon representing the circle is defined as error_distance. The smaller the difference, the closer the polygon is to the ideal circle. The following table is designed to help capture how the radius of a circle affects the number of sides of a polygon given different inputs. The minimum number of edges is 4 and the maximum is 1000.

ElasticSearch complete directory

Elasticsearch is the basic application of Elasticsearch.Elasticsearch Mapping is the basic application of Elasticsearch.Elasticsearch is the basic application of Elasticsearch Elasticsearch tF-IDF algorithm and advanced search 8.Elasticsearch ELK