es - elasticsearch mapping - field data type - 25

76 阅读1分钟

世界上并没有完美的程序,但是我们并不因此而沮丧,因为写程序就是一个不断追求完美的过程。

问 :geo_shape有什么特点?
答 :
在这里插入图片描述

问 :geo_shape如何索引?
答 :

# geo_shape
PUT /geo_shape_test
{
  "mappings" : {
    "properties" : {
      "my_geo_shape" : {"type" : "geo_shape"}
    }
  }
}
 
# 索引 - 点
POST /geo_shape_test/_doc/1
{
  "my_geo_shape" : {
    "type"        : "point",
    "coordinates" : [-77, 38]
  }
}


# 索引 - 线
POST /geo_shape_test/_doc/2
{
  "my_geo_shape" : {
    "type"        : "linestring",
    "coordinates" : [[-77, 38], [-78, 88]]
  }
}

# 索引 - 多边形
POST /geo_shape_test/_doc/3
{
  "my_geo_shape" : {
    "type"        : "polygon",
    "coordinates" : [[[100, 0], [101, 0], [101, 1], [100, 1], [100, 0]]]
  }
}

# 索引 - 多边形
POST /geo_shape_test/_doc/4
{
  "my_geo_shape" : {
    "type"        : "polygon",
    "coordinates" : [
        [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ],
      [ [100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2] ]
    ]
  }
}


# 索引 - 多个点
POST /geo_shape_test/_doc/5
{
  "my_geo_shape" : {
    "type"        : "multipoint",
    "coordinates" : [[78, 45], [67, 56]]
  }
}


# 索引 - 多条线
POST /geo_shape_test/_doc/6
{
  "my_geo_shape" : {
    "type"        : "multilinestring",
    "coordinates" : [
      [[34, 56], [78, 89], [36, 57], [89, 65]],
      [[78, 56], [98, 65], [45, 34], [65, 23]]
    ]
  }
}

# 索引 - 多个多边形
POST /geo_shape_test/_doc/7
{
  "my_geo_shape" : {
    "type"        : "multipolygon",
    "coordinates" : [
      [ [[102.0, 2.0], [103.0, 2.0], [103.0, 3.0], [102.0, 3.0], [102.0, 2.0]] ],
      [ [[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]],
        [[100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2]] ]
    ]
  }
}


# 索引 - 组合索引
POST /geo_shape_test/_doc/8
{
  "my_geo_shape" : {
    "type"       : "geometrycollection",
    "geometries" : [
      {
        "type": "point",
        "coordinates": [100.0, 0.0]
      },
      {
        "type": "linestring",
        "coordinates": [ [101.0, 0.0], [102.0, 1.0] ]
      }
    ]
  }
}


# 索引 - 信封 - 范围
POST /geo_shape_test/_doc/9
{
  "my_geo_shape" : {
    "type"        : "envelope",
    "coordinates" : [[100, 9], [101, 0]]
  }
}

# 索引 - 圆 - (不支持)
POST /geo_shape_test/_doc/10
{
  "my_geo_shape" : {
    "type"        : "circle",
    "coordinates" : [101, 1],
    "radius"      : "100m"
  }
}