赞
踩
PUT /secisland
{
"settings": {
"number_of_shards":3,
"number_of_replicas":1
}
}
DELETE /secisland/
GET /secisland/
#返回内容 { "secisland": { "aliases": {}, "mappings": {}, "settings": { "index": { "creation_date": "1584587482430", "number_of_shards": "3", "number_of_replicas": "1", "uuid": "949RnFG2S4aX_cN1m3grlA", "version": { "created": "5030099" }, "provided_name": "secisland" } } } }
由返回类容可以看出,索引还可以配置mappings、aliases属性。
PUT /secisland/_settings
{
#将副本分片数量修改为1
"number_of_replicas": 1
}
说明:关闭的索引只能够显示索引元数据,不能够进行读写操作。
语法
#关闭
POST /secisland/_close
#打开
POST /secisland/_open
添加索引名为secisland,文档类型log,字段message,字段类型字符串
PUT /secisland
{
"mappings": {
"log":{
"properties": {
"message":{
"type": "string"
}
}
}
}
}
向已存在索引secisland增加新的字段映射 , 也可用于修改字段映射
PUT /secisland/_mapping/log
{
"properties": {
"user_name":{
"type": "string"
}
}
}
获取类型映射
GET /secisland/_mapping/log
获取字段映射
GET /secisland/_mapping/log/field/message
说明:elasticsearch可以对一个或多个索引指定别名,通过别名可以查询到一个或多个索引内容。
POST /_aliases
{
"actions":[
{
"add":{"index":"secisland","alias":"alias1"}
}
]
}
POST /_aliases
{
"actions":[
{
"remove":{"index":"secisland","alias":"alias1"}
}
]
}
通过过滤索引指定别名提供了对索引查看的不同视图。
POST _aliases
{
"actions": [
{
"add": {
"index": "test1","alias": "alias2",
"filter": {"term": {
"user": "kimchy"
}}
}
}
]
}
#新增分词器
PUT /secisland/_settings
{
"analysis": {
"analyzer": {
"content":{
"type":"custom",
"tokenizer":"whitespace"
}
}
}
}
注意:添加分析器之前,必须先关闭索引,添加后再打开索引。
GET /secidland/_settings
索引分析:把文本拆分为一个单词,为倒排索引做准备
es中一个分析器(analyzes)由字符过滤器、分词器(tokenizer)以及标记过滤器组成。
测试分析器
POST /_analyze
{
"analyzer": "standard",
"text": "this is a test"
}
自定义分析器
POST /_analyze
{
"tokenizer": "keyword",
"filter":["lowercase"],
"char_filter": ["html_strip"],
"text": "this is a <b> tTest </b>"
}
获取指定索引的统计数据
GET /index1/_status
GET /secisland/_segments
GET /secisland/_recovery
GET /secisland/_shard_stores
刷新接口可以明确刷新一个或多个索引,使之前最后一次刷新之后的所有操作被执行。
POST /secisland/_refresh
冲洗(flush)接口可以通过接口冲洗一个或多个索引。索引主要通过执行冲洗将数据保存到索引存储并清除内部事务日志,以此来释放索引的内存空间。默认,es使用内存启发式算法来自动触发冲洗操作的请求来清理内存
POST /secisland/_flush
文档类似于数据库中的一条记录,文档必须包含在一个索引中。
PUT /secisland/secilog/1
{
"collect_type":"syslog",
"collect_date":"2020-03-19"
}
1.创建文档时,如果索引不存在,会自动创建索引,并自动映射每个字段类型。
2.创建文档时不指定ID,系统会自动创建一个不重复的随机数。
POST /secisland/secilog/1/_update
{
"doc":{
"collect_type":"systemlog"
}
}
GET /secisland/secilog/1
POST /_megt
{
"docs":[
{"_index":"secisland","_type":"secilog","_id":"1"},
{"_index":"secisland","_type":"secilog","_id":"2"}
]
}
分成action、metadata和doc三部份
action : 必须是以下4种选项之一
index(最常用) : 如果文档不存在就创建他,如果文档存在就更新他
create : 如果文档不存在就创建他,但如果文档存在就返回错误使用时一定要在metadata设置_id值,他才能去判断这个文档是否存在
update : 更新一个文档,如果文档不存在就返回错误使用时也要给_id值,且后面文档的格式和其他人不一样
delete : 删除一个文档,如果要删除的文档id不存在,就返回错误使用时也必须在metadata中设置文档_id,且后面不能带一个doc,因为没意义,他是用_id去删除文档的.
metadata : 设置这个文档的metadata,像是_id、_index、_type…
doc : 就是一般的文档格式
POST /_bulk
{ "index" : { "_index" : "test", "_type" : "_doc", "_id" : "1" } }
{ "field1" : "value1" }
{ "delete" : { "_index" : "test", "_type" : "_doc", "_id" : "2" } }
{ "create" : { "_index" : "test", "_type" : "_doc", "_id" : "3" } }
{ "field1" : "value3" }
{ "update" : {"_index" : "test", "_type" : "_doc", "_id" : "1" } }
{ "doc" : {"field2" : "value2"} }
“test”, “_type” : “_doc”, “_id” : “1” } }
{ “field1” : “value1” }
{ “delete” : { “_index” : “test”, “_type” : “_doc”, “_id” : “2” } }
{ “create” : { “_index” : “test”, “_type” : “_doc”, “_id” : “3” } }
{ “field1” : “value3” }
{ “update” : {"_index" : “test”, “_type” : “_doc”, “_id” : “1” } }
{ “doc” : {“field2” : “value2”} }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。