方式二:安装elasticsearch-rtf,下载:https://nowjava.com/download/31178,本文介绍的方法。
什么是Elasticsearch-RTF? RTF是Ready To Fly的缩写,在航模里面,表示无需自己组装零件即可直接上手即飞的航空模型,Elasticsearch-RTF是针对中文的一个发行版,即使用最新稳定的elasticsearch版本,并且帮你下载测试好对应的插件,如中文分词插件等,目的是让你可以下载下来就可以直接的使用(虽然es已经很简单了,但是很多新手还是需要去花时间去找配置,中间的过程其实很痛苦),当然等你对这些都熟悉了之后,你完全可以自己去diy了,跟linux的众多发行版是一个意思。
下载:
Elasticsearch-head是一款专门针对于Elasticsearch的客户端工具
git clone git://github.com/mobz/elasticsearch-head.git
cd elasticsearch-head
npm install
npm run start
注:npm install 之后若出现错误,可以删除node_mudlues文件夹,npm install grunt-cli -g,npm install grunt -g,然后在npm install
浏览器输入127.0.0.1:9100
Kibana 是为 Elasticsearch设计的开源分析和可视化平台。你可以使用 Kibana 来搜索,查看存储在 Elasticsearch 索引中的数据并与之交互。你可以很容易实现高级的数据分析和可视化,以图标的形式展现出来。
本网下载:kibana下载(如果其它网站下载要注意与elasticsearch版本一致)
下载之后,进入bin目录,执行命令:
kibana.bat
浏览器输入127.0.0.1:5601
elasticsearch | mysql |
index(索引) | 数据库 |
type(类型) | 表 |
document(文档) | 行 |
fields | 列 |
# 索引初始化
PUT lagou
{
"settings": {
"index": {
"number_of_shards": 5, # 分片
"number_of_replicas": 1 # 备份
}
}
}
GET lagou/_settings
GET _all/_settings
GET .kibana,lagou/_settings
GET _settings
# 修改settings
PUT lagou/_settings
{
"number_of_replicas": 2
}
# 获取索引信息
GET _all
GET lagou
# 新建/保存文档
# 方式一
PUT lagou/job/1
{
"title": "python爬虫分布式开发",
"salary_min":15000,
"city":"北京",
"company":{
"name":"百度",
"company_addr":"北京市软件园"
},
"publish_date":"2019-06-15",
"comments":15
}
# 新建文档
# 方式二
POST lagou/job/
{
"title": "python django 开发工程师",
"salary_min":30000,
"city":"上海",
"company":{
"name":"美团科技",
"company_addr":"北京市软件园A区"
},
"publish_date":"2019-06-15",
"comments":120
}
GET lagou/job/1
GET lagou/job/1?_source=title
GET lagou/job/1?_source=title,city
GET lagou/job/1?_source
# 修改文章
# 方式一
PUT lagou/job/1
{
"title": "python爬虫分布式开发",
"salary_min":18000,
"city":"广州",
"company":{
"name":"百度",
"company_addr":"北京市软件园"
},
"publish_date":"2019-06-15",
"comments":15
}
# 方式二:修改修改某一字段
POST lagou/job/1/_update
{
"doc": {
"comments":20
}
}
# 删除
DELETE lagou/job/1
DELETE lagou/job
DELETE lagou
# 批量操作
数据准备
POST lagou/job1/1
{
"title": "python django 开发工程师",
"salary_min":30000,
"city":"上海",
"company":{
"name":"美团科技",
"company_addr":"北京市软件园A区"
},
"publish_date":"2019-06-15",
"comments":120
}
POST lagou/job1/2
{
"title": "python django 开发工程师",
"salary_min":30000,
"city":"上海",
"company":{
"name":"美团科技",
"company_addr":"北京市软件园A区"
},
"publish_date":"2019-06-15",
"comments":120
}
POST lagou/job2/1
{
"title": "python django 开发工程师",
"salary_min":30000,
"city":"上海",
"company":{
"name":"美团科技",
"company_addr":"北京市软件园A区"
},
"publish_date":"2019-06-15",
"comments":120
}
POST lagou/job2/2
{
"title": "python django 开发工程师",
"salary_min":30000,
"city":"上海",
"company":{
"name":"美团科技",
"company_addr":"北京市软件园A区"
},
"publish_date":"2019-06-15",
"comments":120
}
mget批量获取
GET _mget
{
"docs":[
{"_index":"lagou",
"_type":"job1",
"_id":1
},
{"_index":"lagou",
"_type":"job2",
"_id":2
}
]
}
GET lagou/_mget
{
"docs":[
{
"_type":"job1",
"_id":1
},
{
"_type":"job2",
"_id":2
}
]
}
GET lagou/job1/_mget
{
"docs":[
{
"_id":1
},
{
"_id":2
}
]
}
GET lagou/job1/_mget
{
"ids":[1,2]
}
bulk增删改查
POST _bulk
{"index":{"_index":"lagou","_type":"job1","_id":"3"}}
{"title": "python django 开发工程师","salary_min":30000,"city":"上海","company":{"name":"美团科技","company_addr":"北京市软件园A区"},"publish_date":"2019-06-15","comments":120}
{"index":{"_index":"lagou","_type":"job2","_id":"3"}}
{"title": "python django 开发工程师","salary_min":30000,"city":"上海","company":{"name":"美团科技","company_addr":"北京市软件园A区"},"publish_date":"2019-06-15","comments":120}
POST _bulk
{"create":{"_index":"lagou","_type":"job1","_id":"3"}}
{"title": "python django 开发工程师","salary_min":30000,"city":"上海","company":{"name":"美团科技","company_addr":"北京市软件园A区"},"publish_date":"2019-06-15","comments":120}
POST _bulk
{"delete":{"_index":"lagou","_type":"job1","_id":"3"}}
POST _bulk
{"update":{"_index":"lagou","_type":"job1","_id":"3"}}
{"doc":{"title": "python django 开发工程师","salary_min":30000,"city":"上海","company":{"name":"美团科技","company_addr":"北京市软件园A区"},"publish_date":"2019-06-15","comments":120}}
本文系作者在时代Java发表,未经许可,不得转载。
如有侵权,请联系nowjava@qq.com删除。