1、elasticsearch安装
2、elasticsearch概念
3 、elasticsearch的crud、批量操作
4、elasticsearch映射mapping
5、elasticsearch查询
CURD操作
#文档es的文档和索引CRUD操作
#索引初始化操作
#指定分片5个和副本的数量1个
#shards一旦设置不能修改
PUT lagou
{
"settings": {
"index":{
"number_of_shards":5,
"number_of_replicas":1
}
}
}
#获取所有索引
GET _all
#获取lagou索引
GET lagou
#获取某个索引的setting
GET lagou/_settings
#获取所有索引的setting
GET _all/_settings
GET _settings
#获取指定几个索引的setting
GET lagou,.kibana/_settings
#更新索引
PUT lagou/_settings
{
"number_of_replicas": 2
}
#保存文档(index/type/id)
PUT lagou/job/1
{
"title":"python分布式爬虫开发" ,
"salary_min":15000 ,
"city":"北京" ,
"publish_date":"2018-08-02" ,
"comments":15,
"company":{
"name":"百度",
"company_addr":"北京市软件园"
}
}
#POST保存文档(index/type/)id会自动生成uuid
POST /lagou/job/
{
"title":"python django 开发工程师",
"salary_min":30000,
"city":"上海" ,
"publish_date":"2018-07-12",
"comments":20,
"company":{
"name":"美团科技",
"company_addr":"上海市软件园A区"
}
}
#获取指定字段
GET lagou/job/1?_source=title,city
#修改(全部修改)
PUT lagou/job/1
{
"title":"python分布式爬虫开发1"
}
#增量修改
POST lagou/job/2/_update
{
"doc":{
"comments":10
}
}
#删除
DELETE lagou/job/1
DELETE lagou/job
DELETE lagou
批量操作
#批量获取
GET _mget
{
"docs":[
{
"_index":"lagou",
"_type":"job",
"_id":"2"
},{
"_index":"lagou",
"_type":"job1",
"_id":"1"
}
]
}
GET lagou/_mget
{
"docs":[
{
"_type":"job",
"_id":"2"
},{
"_type":"job1",
"_id":"1"
}
]
}
GET lagou/_mget
{
"ids":[1,2]
}
bulk批量操作
批量导入可以合并多个操作、比如index,delete,update,create等。也可以将一个索引导入到另外一个索引
POST _bulk
{"index":{"_index":"lagou","_type":"job","_id":"2"}}
{"title":"python分布式爬虫开发" ,"salary_min":15000 ,"city":"北京" ,"publish_date":"2018-08-02","comments":16,"company":{"name":"百度","company_addr":"北京市软件园2"}}
{"index":{"_index":"lagou","_type":"job1","_id":"1"}}
{"title":"python分布式爬虫开发" ,"salary_min":15000 ,"city":"北京" ,"publish_date":"2018-08-02","comments":16,"company":{"name":"百度","company_addr":"北京市软件园3"}}