ES 操作命令

初始化library索引
POST http://127.0.0.1:9200/library/
{
	"settings": {
		"index": {
			"number_of_shards": 5,
			"number_of_replicas": 1
		}
	}
}
上面的number_of_replicas还可以换成
blocks.read_only: 设为true,则当前索引只允许读,不允许写或更新
blocks.read:          设为true,则禁止读操作
blokcs.write:          设为true,则禁止写操作
blocks.metadata:   设为true,则禁止对metadata操作

   

library索引添加Mapping映射
POST http://127.0.0.1:9200/library

 

{
	"properties": {
		"title": {
			"type": "string"
		},
		"name": {
			"type": "string",
			"index": "not_analyzed"
		},
		"publish_date": {
			"type": "date",
			"index": "not_analyzed"
		},
		"price": {
			"type": "double"
		},
		"number": {
			"type": "integer"
		}
	}
}

 

获取这个集群内所有的映射信息
GET http://127.0.0.1:9200/_all/_mapping

 

获取某个索引的映射信息
GET http://127.0.0.1:9200/library/_mapping

 

获取某个索引下某个type的映射信息 写道
GET http://127.0.0.1:9200/library/_mapping/books

 

添加一个索引记录
POST http://127.0.0.1:9200/library/books/1

 

{
	"title": "Elasticsearch: The Definitive Guide ",
	"name": {
		"first": "Zachary",
		"last": "Tong"
	},
	"publish_data": "2015-02-06",
	"price": "49.99"
}

 

获取索引记录
GET http://127.0.0.1:9200/library/books/1

 

通过_source获取指定的字段
GET http://127.0.0.1:9200/library/books/1?_source=title,price

 

更新同一个ID下的文档,可以通过覆盖的方式更新
PUT http://127.0.0.1:9200/library/books/1

 

通过_update API的方式单独更新你想要更新的字段
POST http://127.0.0.1:9200/library/books/1/_update

 

{
	"doc": {
		"price": 10
	}
}
 
删除一个文档的方法
DELETE http://127.0.0.1:9200/library/books/1

 

更新修改Mapping映射 写道
mapping一旦建立,就不能修改现有的字段映射
如果要推倒现有的映射,你得重新建立一个索引,然后重新定义映射
然后把之前索引里的数据导入到新建立的索引里
具体的方法:
1.给现有的索引里的数据定义一个别名,并且把现有的索引指向这个别名
2.运行:PUT /现有索引/_alias/别名A
3.新创建一个索引,定义好最新的映射
4.将别名指向新的索引,并且取消之前索引的指向
5.运行:POST /_aliases

 

{
	"actions": [{
			"remove": {
				"index": "现有索引名",
				"alias": "别名A"
			}
		},
		{
			"add": {
				"index": "新建索引名",
				"alias": "别名A"
			}
		}
	]
}

 

删除映射
DELETE /library/books
DELETE /library/books/_mapping
DELETE /library/_mapping/books

 

简单的查询
指定index名以及type名的搜索
GET /library/books/_search?q=title:elasticsearch
指定index名没有type的搜索
GET /llibrary/_search?q=title:mongodb
即没有index名也没有type名的搜索
GET /_search?q=title:elasticsearch

 

转自:https://blog.csdn.net/tanfei113/article/details/51934037

猜你喜欢

转载自rjkfloveyou.iteye.com/blog/2423483