`
Franciswmf
  • 浏览: 779051 次
  • 性别: Icon_minigender_1
  • 来自: 上海
文章分类
社区版块
存档分类
最新评论

windows环境安装elasticsearch-7.10.2及插件elasticsearch-head、插件analysis-ik分词器

 
阅读更多
1、官网下载es安装包:如elasticsearch-7.10.2-windows-x86_64.zip
解压后进入bin目录:运行elasticsearch.bat即可,默认的端口:9200
访问:http://localhost:9200/

2、可视化工具elasticsearch-head
通过elasticsearch-head可以很方便的查看ES的运行状态和数据、查看es集群状态。elasticsearch-head依赖于node环境。
2.1 安装node环境:node -v 查看
2.2 安装grunt:
	npm install -g grunt-cli
	查看版本号 grunt -version
2.3 安装elasticsearch-head插件
下载:git clone git://github.com/mobz/elasticsearch-head.git
安装:
cd elasticsearch-head
npm install (中间卡住时可手动下载:phantomjs-2.1.1-windows.zip到C:\Users\User\AppData\Local\Temp\phantomjs,地址:https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs-2.1.1-windows.zip )
运行:
npm run start
访问: 
http://localhost:9100/
2.4 修改es使用的参数使head可以访问es
编辑elasticsearch-7.10.2\config\elasticsearch.yml文件
# 跨域设置:head插件访问es
http.cors.enabled: true 
http.cors.allow-origin: "*"
2.5 重启es
到此,elasticsearch和elasticsearch-head安装成功。

3、将elasticSearch安装为Windows服务(非必须)
进入elasticsearch/bin目录下执行: elasticsearch-service.bat install 即可
ps:
elasticsearch-service.bat install: 安装elasticsearch服务
elasticsearch-service.bat remove: 删除已安装的elasticsearch服务
elasticsearch-service.bat start: 启动elasticsearch服务
elasticsearch-service.bat stop:  停止服务
elasticsearch-service.bat manager: 启动GUI来管理已安装的服务

4 安装IK分词器
IK分词器,即分词插件elasticsearch-analysis-ik
https://github.com/medcl/elasticsearch-analysis-ik/releases
方式一:
在进入elasticsearch/plugins目录下新建analysis-ik文件夹,将elasticsearch-analysis-ik-7.10.2.zip解压后的文件拷贝进去,重启es即可;
方式二:
进入elasticsearch/bin目录下执行执行插件安装命令:
elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.10.2/elasticsearch-analysis-ik-7.10.2.zip
现在支持ik_smart与ik_max_word两种分词:ik_max_word分词比ik_smart分词粒度更细
{
"analyzer":"ik_smart",
"text": "北京有北京aaa广场"
}
{
"analyzer": "ik_max_word",
"text":"北京有北京aaa广场"
}
{"query":{"match_all":{}}} 
 
{"query":{"match":{{ "content" : "北京" }}}} 
各种es的API:
_search
_analyze

5、使用es-head工具操作es
es             mysql
-------------------------
index          表
document        行
field           列
mapping         表结构
--------------------------
新增索引字段:
http://localhost:9200/student/chinese_scores/_mapping?include_type_name=true

{
	"chinese_scores": {
		"properties": {
			"id": {
				"type": "keyword"
			},
			"name": {
				"type": "keyword"
			},
			"age": {
				"type": "integer"
			},
			"birth": {
				"type": "date",
				"format": "yyyy-MM-dd HH:mm:ss"
			},
			"course": {
				"type": "keyword"
			},
			"score": {
				"type": "double"
			}
		}
	}
}
--新增数据
http://localhost:9200/student/chinese_scores/1

{
	"id": "100",
	"name": "张三",
	"age": 13,
	"birth": "2000-10-01 09:30:08",
	"course": "语文",
	"score": 98.5
}

http://localhost:9200/student/chinese_scores/2
{
"id": "101",
"name":"李四",
"age": 14,
"birth": "2000-08-01 09:30:08",
"course":"语文",
"score": 96.5
}

http://localhost:9200/student/chinese_scores/3
{
"id": "102",
"name":"Luis",
"age": 15,
"birth": "2000-09-01 09:30:08",
"course":"语文",
"score": 99.5
}
--查询数据1:指定索引 http://localhost:9200/student/chinese_scores/_search
{
	"query": {
		"match": {
			"name": "张三"
		}
	}
}
--查询数据2:全部索引 http://localhost:9200/_search
{
	"query": {
		"match": {
			"name": "张三"
		}
	}
}

参考:
https://www.cnblogs.com/hualess/p/11540477.html
https://mp.weixin.qq.com/s/ie7GVbo1g1HKm-v8T8W6Ow
https://www.cnblogs.com/java-spring/p/11766450.html

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics