elasticsearch创建索引加载数据(查询地名地址)

文章提供了Elasticsearch的下载及运行指南,包括如何通过cmd执行数据入库脚本和创建索引的步骤。此外,还详细介绍了使用Elasticsearch进行数据处理,特别是对高德地图数据的处理,以及自定义的Pinyin分析器设置,便于中文搜索。最后提到了使用Postman测试查询接口的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.第一步,下载压缩包,解压即可用
ES库解压版,下载后进入到bin目录下有一个 elasticsearch.bat 双击运行即可
链接:https://pan.baidu.com/s/1lo7Nhb0ytAIXCQFCYDmGMg
提取码:a123

ES库数据入库使用,使用方式:下载后解压,通过cmd进入到bin目录下,执行数据入库脚本的命令:elasticdump --output=http://127.0.0.1:9200/mgs_global_poi --input=D:\ES\global_addr.json --limit=1000

链接:https://pan.baidu.com/s/1akLK68C0pHT_K7hmeH6Oaw
提取码:b321

2.索引的创建脚本我放到最下面

解压后如下:在这里插入图片描述
2.运行ES,进入bin目录下双击 elasticsearch.bat
在这里插入图片描述
3.运行成功测试,浏览器输入:http://localhost:9200 ,出现以下信息启动成功
在这里插入图片描述
创建索引,下载压缩包,然后解压
链接:https://pan.baidu.com/s/1KCt2ra0hpU2apVwQd6Cf7Q
提取码:a456

解压后打开index.html在这里插入图片描述
点击进入
在这里插入图片描述
添加索引脚本,勾选易读,再点击验证JSON,然后点击提交请求
大家可能没有索引脚本,我这边提供一个,下载下来复制粘贴到第一步的框框里就行
链接:https://pan.baidu.com/s/1TA4vYmRBf5jlx9Kyk_Uf4w
提取码:b321
在这里插入图片描述
提交后创建成功
在这里插入图片描述
然后可以通过概览查看,图下为刚刚所新加索引
在这里插入图片描述
ES库本身自己就封装了一套对外查询的接口,可以通过postman测试
在这里插入图片描述

这里我多说一句关于数据怎么入库,我的数据是高德趴的数据,一个大JSON,可以通过 elasticsearch-head-master,通过cmd窗口进入bin目录下然后执行数据加载的脚本命令:elasticdump --output=http://127.0.0.1:9200/mgs_global_poi --input=D:\ES\global_addr.json --limit=1000

索引脚本(粘贴复制直接提交就行)

{
	"settings": {
		"index": {
			"routing": {
				"allocation": {
					"include": {
						"_tier_preference": "data_content"
					}
				}
			},
			"refresh_interval": "15s",
			"number_of_shards": "5",
			"max_result_window": "2147483647",
			"analysis": {
				"filter": {
					"pinyin_simple_filter": {
						"keep_joined_full_pinyin": "true",
						"lowercase": "true",
						"none_chinese_pinyin_tokenize": "false",
						"padding_char": " ",
						"keep_original": "true",
						"keep_first_letter": "true",
						"keep_separate_first_letter": "false",
						"type": "pinyin",
						"keep_full_pinyin": "false"
					},
					"pinyin_full_filter": {
						"keep_joined_full_pinyin": "true",
						"lowercase": "true",
						"keep_original": "false",
						"keep_first_letter": "false",
						"keep_separate_first_letter": "false",
						"type": "pinyin",
						"keep_none_chinese": "false",
						"limit_first_letter_length": "50",
						"keep_full_pinyin": "true"
					}
				},
				"analyzer": {
					"pinyiSimpleIndexAnalyzer": {
						"filter": [
							"pinyin_simple_filter",
							"lowercase"
						],
						"type": "custom",
						"tokenizer": "ik_max_word"
					},
					"pinyinFullIndexAnalyzer": {
						"filter": [
							"asciifolding",
							"lowercase",
							"pinyin_full_filter"
						],
						"type": "custom",
						"tokenizer": "ik_max_word"
					},
					"ik_pinyin_analyzer": {
						"filter": [
							"asciifolding",
							"lowercase",
							"pinyin_full_filter",
							"word_delimiter"
						],
						"type": "custom",
						"tokenizer": "ik_smart"
					},
					"ikIndexAnalyzer": {
						"filter": [
							"asciifolding",
							"lowercase"
						],
						"type": "custom",
						"tokenizer": "ik_max_word"
					}
				}
			},
			"number_of_replicas": "2"
		}
	},
	"mappings": {
		"dynamic_templates": [],
		"properties": {
			"center_location": {
				"type": "geo_point"
			},
			"create_time": {
				"type": "keyword"
			},
			"create_user": {
				"type": "keyword"
			},
			"data_id": {
				"type": "keyword"
			},
			"data_name": {
				"type": "text",
				"analyzer": "pinyinFullIndexAnalyzer"
			},
			"dataset_id": {
				"type": "keyword"
			},
			"datasource_id": {
				"type": "keyword"
			},
			"geo_type": {
				"type": "keyword"
			},
			"is_share": {
				"type": "integer"
			},
			"link_url": {
				"type": "keyword"
			},
			"md5_id": {
				"type": "keyword"
			},
			"place_adcode": {
				"type": "keyword"
			},
			"place_address": {
				"type": "text",
				"analyzer": "pinyinFullIndexAnalyzer"
			},
			"place_city": {
				"type": "keyword"
			},
			"place_country": {
				"type": "keyword"
			},
			"place_countryside": {
				"type": "text",
				"fields": {
					"keyword": {
						"type": "keyword",
						"ignore_above": 256
					}
				}
			},
			"place_district": {
				"type": "keyword"
			},
			"place_doorplate": {
				"type": "text"
			},
			"place_email": {
				"type": "keyword"
			},
			"place_icon": {
				"type": "keyword"
			},
			"place_labels": {
				"type": "text"
			},
			"place_province": {
				"type": "keyword"
			},
			"place_summary": {
				"type": "text"
			},
			"place_telnum": {
				"type": "keyword"
			},
			"place_town": {
				"type": "text",
				"fields": {
					"keyword": {
						"type": "keyword",
						"ignore_above": 256
					}
				}
			},
			"place_website": {
				"type": "keyword"
			},
			"smgeometry": {
				"type": "geo_shape"
			},
			"type_code": {
				"type": "long"
			},
			"type_name": {
				"type": "keyword"
			},
			"update_time": {
				"type": "keyword"
			},
			"update_user": {
				"type": "keyword"
			}
		}
	}
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

七月吃橘子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值