IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 大数据 -> ElasticSearch中Shape类型操作 -> 正文阅读

[大数据]ElasticSearch中Shape类型操作

说明

????????1、用户必须明确的将字段type定义为shape类型

? ? ? ? 2、官方文档地址:https://www.elastic.co/guide/en/elasticsearch/reference/7.4/shape-queries.html

? ? ? ? 3、本文档中ES存入数据,分别采用GeoJSON和WKT方式,查询都是通过GeoJSON方式进行查询

? ? ? ? 4、7.4(包含)以后的版本才开始支持shape操作

一、GeoJSON方式

? ? ? ? 1、创建索引

PUT /example_geojson

{
  "mappings": {
    "properties": {
      "geometry": {
        "type": "shape"
      }
    }
  }

? ? ? ? 2、插入数据

POST /example_geojson/_doc

{
  "name": "Lucky Landing",
  "geometry": {
    "type": "point",
    "coordinates": [ x, y ]
}

? ? ? ? 3、查询数据

POST /example_geojson/_search

查询方式1(矩形):
{
  "query": {
    "shape": {
      "geometry": {
        "shape": {
          "type": "envelope",
          "coordinates": [ 
            [ 116.01, 39.01 ], 
            [ 116.02, 39.02 ]
          ]
        },
        "relation": "within"
      }
    }
  }
}

查询方式2(多边形):
{
  "query": {
    "shape": {
      "geometry": {
        "shape": {
          "type": "polygon",
          "coordinates": [[
              [116.01,39.01],
              [116.02,39.02],
              [116.03,39.03],
              [116.04,39.04],
              [116.05,39.05],
              [116.06,39.06],
              [116.01,39.01]
            ]]
        },
        "relation": "within"
      }
    }
  }
}

查询方式3(多面):
{
  "query": {
    "shape": {
      "geometry": {
        "shape": {
          "type": "multipolygon",
          "coordinates": [
            [[
              [116.01,39.01],
              [116.02,39.02],
              [116.03,39.03],
              [116.04,39.04],
              [116.05,39.05],
              [116.06,39.06],
              [116.01,39.01]
            ]],
            [[
              [116.01,39.01],
              [116.02,39.02],
              [116.03,39.03],
              [116.04,39.04],
              [116.01,39.01]
            ]]
          ]
        },
        "relation": "within"
      }
    }
  }
}

注:以上数据都是虚拟数据,仅提供格式参照

? ? ? ? ? ? ? ? 4、返回数据

{
	"took": 2,
	"timed_out": false,
	"_shards": {
		"total": 1,
		"successful": 1,
		"skipped": 0,
		"failed": 0
	},
	"hits": {
		"total": {
			"value": 3,
			"relation": "eq"
		},
		"max_score": 1,
		"hits": [{
				"_index": "test02",
				"_type": "_doc",
				"_id": "km1t4XoBGyDewCtudsly",
				"_score": 1,
				"_source": {
					"name": "测试01",
					"geometry": {
						"type": "point",
						"coordinates": [
							116.01,
							39.01
						]
					}
				}
			},
			{
				"_index": "test02",
				"_type": "_doc",
				"_id": "k21t4XoBGyDewCtuwsmh",
				"_score": 1,
				"_source": {
					"name": "测试02",
					"geometry": {
						"type": "point",
						"coordinates": [
							116.02,
							39.02
						]
					}
				}
			},
			{
				"_index": "test02",
				"_type": "_doc",
				"_id": "lG1t4XoBGyDewCtu_slb",
				"_score": 1,
				"_source": {
					"name": "测试03",
					"geometry": {
						"type": "point",
						"coordinates": [
							116.03,
							39.03
						]
					}
				}
			}
		]
	}
}

? ? ? ? ? ? ? ? 5、mapping信息

"mappings": {
	"_doc": {
		"properties": {
			"name": {
				"type": "text",
				"fields": {
					"keyword": {
						"ignore_above": 256,
						"type": "keyword"
					}
				}
			},
			"geometry": {
				"type": "shape"
			}
		}
	}
}

二、Well-Known Text(WKT)方式

? ? ? ? ? ? ? ? 1、创建索引

PUT /example_wkt
{
  "mappings": {
    "properties": {
      "geometry": {
        "type": "shape"
      }
    }
  }
}

? ? ? ? ? ? ? ? 2、插入数据

POST /example_wkt/_doc
{
  "geometry": "POINT (x y)",
  "name": "testName"
}

? ? ? ? ? ? ? ? 3、查询数据

POST /example_wkt/_search

查询方式1(矩形):
{
  "query": {
    "shape": {
      "geometry": {
        "shape": {
          "type": "envelope",
          "coordinates": [ 
            [ 116.01, 39.01 ], 
            [ 116.02, 39.02 ]
          ]
        },
        "relation": "within"
      }
    }
  }
}

查询方式2(多边形):
{
  "query": {
    "shape": {
      "geometry": {
        "shape": {
          "type": "polygon",
          "coordinates": [[
              [116.01,39.01],
              [116.02,39.02],
              [116.03,39.03],
              [116.04,39.04],
              [116.05,39.05],
              [116.06,39.06],
              [116.01,39.07]
            ]]
        },
        "relation": "within"
      }
    }
  }
}

查询方式3(多面):
{
  "query": {
    "shape": {
      "geometry": {
        "shape": {
          "type": "multipolygon",
          "coordinates": [
            [[
              [116.01,39.01],
              [116.02,39.02],
              [116.03,39.03],
              [116.04,39.04],
              [116.05,39.05],
              [116.06,39.06],
              [116.01,39.01]
            ]],
            [[
              [116.01,39.01],
              [116.02,39.02],
              [116.03,39.03],
              [116.04,39.04],
              [116.01,39.05]
            ]]
          ]
        },
        "relation": "within"
      }
    }
  }
}

注:以上数据都是虚拟数据,仅提供格式参照

? ? ? ? ? ? ? ? 4、返回数据

{
  "took": 2,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 3,
      "relation": "eq"
    },
    "max_score": 1,
    "hits": [
      {
        "_index": "test03",
        "_type": "_doc",
        "_id": "6G3d5XoBGyDewCtuAMn4",
        "_score": 1,
        "_source": {
          "name": "测试01",
          "geometry": "POINT (116.01 39.01)"
        }
      },
      {
        "_index": "test03",
        "_type": "_doc",
        "_id": "6W3d5XoBGyDewCtuisnl",
        "_score": 1,
        "_source": {
          "name": "测试02",
          "geometry": "POINT (116.02 39.02)"
        }
      },
      {
        "_index": "test03",
        "_type": "_doc",
        "_id": "6m3d5XoBGyDewCtu7snt",
        "_score": 1,
        "_source": {
          "name": "测试03",
          "geometry": "POINT (116.03 39.03)"
        }
      }
    ]
  }
}

? ? ? ? ? ? ? ? 5、mapping信息

"mappings": {
  "_doc": {
    "properties": {
      "name": {
        "type": "text",
        "fields": {
          "keyword": {
            "ignore_above": 256,
            "type": "keyword"
          }
        }
      },
      "geometry": {
        "type": "shape"
      }
    }
  }
}

  大数据 最新文章
实现Kafka至少消费一次
亚马逊云科技:还在苦于ETL?Zero ETL的时代
初探MapReduce
【SpringBoot框架篇】32.基于注解+redis实现
Elasticsearch:如何减少 Elasticsearch 集
Go redis操作
Redis面试题
专题五 Redis高并发场景
基于GBase8s和Calcite的多数据源查询
Redis——底层数据结构原理
上一篇文章      下一篇文章      查看所有文章
加:2021-08-20 15:11:21  更:2021-08-20 15:13:22 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/23 13:17:55-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码