es - elasticsearch mapping - field data type - 24

109 阅读1分钟

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

问 :geo_point有什么特点?
答 :
在这里插入图片描述
问 :geo_point如何使用?
答 :

# geo_point
PUT /geo_point_test
{
  "mappings" : {
    "properties" : {
      "my_geo_point" : {"type" : "geo_point"}
    }
  }
}

# 索引,纬度 - 经度
POST /geo_point_test/_doc/1
{
  "my_geo_point" : {
    "lat" : 18,
    "lon" : 40
  }
}

# 索引,纬度 - 经度
POST /geo_point_test/_doc/2
{
  "my_geo_point" : "30, 78"
}

# 索引, geohash
POST /geo_point_test/_doc/3
{
  "my_geo_point" : "drm3btev3e86"
}

# 索引, 经度 - 纬度
POST /geo_point_test/_doc/4
{
  "my_geo_point" : [80, 43]
}

# 索引,经度 - 纬度
POST /geo_point_test/_doc/5
{
  "my_geo_point" : "POINT (78 40)"
}

# 搜索
GET /geo_point_test/_search
{
  "query" : {
    "geo_bounding_box" : {
      "my_geo_point" : {
        "top_left" : {
          "lat" : 60,
          "lon" : 44
        },
        "bottom_right" : {
          "lat" : 35,
          "lon" : 99
        }
      }
    }
  }
}

# 结果
{
  "took" : 989,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 2,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "geo_point_test",
        "_type" : "_doc",
        "_id" : "4",
        "_score" : 1.0,
        "_source" : {
          "my_geo_point" : [
            80,
            43
          ]
        }
      },
      {
        "_index" : "geo_point_test",
        "_type" : "_doc",
        "_id" : "5",
        "_score" : 1.0,
        "_source" : {
          "my_geo_point" : "POINT (78 40)"
        }
      }
    ]
  }
}