07_Kibana界面操作ES

Kibana界面的API操作ES

1.创建索引

1.1 指定分片数量和备份数量

image

1.2 创建默认

image

 

2. 查看索引

image

2.1 查看单个索引设置

image

2.2 查看所有索引设置

image

3.文档管理

3.1 添加文档

3.1.1 PUT

image

3.1.2 POST方式

可以不指定ID,会自动生成一个ID

image

3.2 查看文档

3.2.1 查看文档全部内容

image

3.2.2 查看文档部分内容

image

 

3.3 修改文档

3.3.1 PUT方式

覆盖

image

3.3.2 POST方式

只修改部分数据,而不是覆盖

image

3.4 删除文档

image

4. 删除索引

image

 

5.批量操作

5.1. _mget

5.1.1 同时获取多个文档

image

5.1.2 同时获取多个文档的部分内容

image

索引相同的话,可以简写为如下形式

image

image

5.2. _bulk

{action:{metadata}}
{requestbody}

action:(行为)

  • create:文档不存在时创建

  • update: 更新文档

  • index:创建新文档或替换已有文档

  • delete:删除一个文档

metadata:_index,_type,_id

5.2.1 创建

image

6. Query查询

6.1 简单查询

image

GET /lib3/user/_search?q=name:lisi

image

# 筛选出包含唱歌的,并且按照年龄从大到小排序
GET /lib3/user/_search?q=internets:changge&sort=age:desc
6.2 term查询和terms查询

会根据倒排索引寻找确切的term,并不知道分词器的存在,适合keywordnumericdate

image

6.3 match查询

知道分词器的存在,会对field进行分词操作,然后再查询

image

6.3.1 multi_match

可以从多个字段中筛选出query包含的词

image

6.3.2 match_phrase

短语匹配

image

6.4 wildcard查询

支持使用通配符*?来进行查询 *代表0或多个字符 ? 表示任意一个字符

image

GET /lib3/user/_search
{
  "query": {
    "wildcard": {
      "name": "zhao*"
    }
  }
}

image

GET /lib3/user/_search
{
  "query": {
    "wildcard": {
      "name": "zhaol?u"
    }
  }
}
6.5 fuzzy查询

实现模糊查询,只能少一个字符,多个字符依然无法查询到

image

高亮

筛选字段和高亮字段要一致

image

6.6 基于中文的查询

安装ik插件

ik_max_word : 会将文本做最细粒度的拆分;尽可能多的拆分出词语 ik_smart: 做最粗粒度拆分;已经被分出的词语不会再被其他词语占有

# 环境构建
PUT /lib4
{
  "settings": {
    "number_of_replicas": 1,
    "number_of_shards": 5
  },
  "mappings": {
    "user" :{
      "properties": {
        "name" : {"type": "text","analyzer": "ik_max_word"},
        "address" : {"type": "text","analyzer": "ik_max_word"},
        "age" : {"type": "integer"},
        "internets" : {"type": "text", "analyzer": "ik_max_word"},
        "birthday" : {"type" : "date"}
      }
    }  
  }
}

image

from:指定初始位置,size表示长度

6.7 指定返回字段
GET /lib4/user/_search
{
  "_source": ["address","name"],
  "query": {
    "match": {
      "internets": "唱歌"
    }
  }
}

image

# include 包含
GET  /lib4/user/_search
{
  "query": {
    "match": {
      "internets": "唱歌"
    }
  }, 
  "_source": {
    "includes": ["name","address"]
  }
}
# 不包含
GET  /lib4/user/_search
{
  "query": {
    "match": {
      "internets": "唱歌"
    }
  }, 
  "_source": {
     "excludes": ["age","birthday"]
  }
}

image

6.8 排序

image

6.9 范围筛选

image

默认值都为true,包含边界值 "include_lower" : false 不包含下边界 "include_upper" : false 不包含上边界

命令行式API操作

2.xx

curl -XPUT localhost:9200/lib -d'{"number_of_replicas": 1}'

6.xx

curl -X PUT "localhost:9200/lib/" -H 'Content-type: application/json' -d '
{
    "settings" : {
        "number_of_shards" : 5,
        "number_of_replicas" : 1
    }
}
'

  

 

posted @ 2019-09-21 10:05  情浅凉心  阅读(1468)  评论(0编辑  收藏  举报