从零学Elasticsearch系列——使用kibana实现ES基本的操作

news/2024/7/7 5:52:26 标签: 全文检索, ELK, Elasticsearch, 引擎, 搜索

系列文章:

一、使用Kibana实现ES基本的操作

进入kibana开发测试工具界面

在这里插入图片描述

查看集群

查看集群健康信息

GET /_cat/health?v
在这里插入图片描述

集群状态(status)

  • Green(正常)
  • Yellow(正常,但是一些副本还没有分配)
  • Red(非正常)

可以使用GET /_cat/health?help查看每个操作返回结果字段的意义

注意:

  1. 这里的GET是RESTful API的请求方式
  2. /_cat/health?help 是RESTful API接口
  3. 你也可以使用PostMan这样的RESTful API测试工具,但是没有提示

使用方式如下:
在这里插入图片描述

查看集群中节点信息

GET /_cat/nodes?v

ip             heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
192.168.23.141            9          91   7    0.10    0.08     0.13 mdi       *      x0vIhEF

查看集群中的索引信息

GET /_cat/indices?v

health status index  uuid                   pri rep docs.count docs.deleted store.size 
yellow open   baizhi BYzhTHMzQIKEiyaKXklueQ   5   1          0            0      1.2kb

简化写法

GET /_cat/indices?v&h=health,status,index

health status index
yellow open   baizhi

索引操作

创建索引

PUT /baizhi

#! Deprecation: the default number of shards will change from [5] to [1] in 7.0.0; if you wish to continue using the default of [5] shards, you must manage this on the create index request or with an index template
{
  "acknowledged": true, # 创建成功返回true
  "shards_acknowledged": true,
  "index": "baizhi"
}

上面的操作使用默认的配置信息创建一个索引

删除索引

DELETE /baizhi

{
  "acknowledged": true
}

创建类型Mapping

PUT /baizhi # 创建index(baizhi)并添加类型mapping(_doc)
{
  "mappings": {
    "_doc": { 
      "properties": { 
        "title":    { "type": "text"  },  # 注意: 字符串常用类型:text类型会分词 keyword类型不会分词
        "name":     { "type": "text"  }, 
        "age":      { "type": "integer" },  
        "created":  {
          "type":   "date", 
          "format": "strict_date_optional_time||epoch_millis"
        }
      }
    }
  }
}

POST /baizhi/user # 创建index(baizhi)后,在指定index中添加类型mapping(user)
{
  "user": { 
      "properties": { 
        "id":    { "type": "text"  }, 
        "name":     { "type": "text"  }, 
        "age":      { "type": "integer" },  
        "created":  {
          "type":   "date", 
          "format": "strict_date_optional_time||epoch_millis"
        }
      }
    }
}

Mapping Type:

  1. 简单类型: text, keyword, date, long, double, boolean or ip
  2. 其它类型: object, geo_point, geo_shape

查看类型mapping

GET /baizhi/_mapping/_doc # 语法:GET /索引名/_mapping/类型名

-------------------------------------------
{
  "baizhi": {
    "mappings": {
      "_doc": {
        "properties": {
          "age": {
            "type": "integer"
          },
          "created": {
            "type": "date"
          },
          "name": {
            "type": "text"
          },
          "title": {
            "type": "text"
          }
        }
      }
    }
  }
}

注意:mapping types将会在ES 7.0版本中移除。原因可参考:https://www.elastic.co/guide/en/elasticsearch/reference/current/removal-of-types.html#_why_are_mapping_types_being_removed

文档操作

新增单个文档

PUT /baizhi/_doc/1 # put /索引名/类型名/id
{				   # request body
  "name":"zs",
  "title":"张三",
  "age":18,
  "created":"2018-12-25"
}

POST /baizhi/_doc
{
  "name":"ls",
  "title":"李四",
  "age":28,
  "created":"2018-12-26"
}
-------------------------------------------------------------
{
  "_index": "baizhi",
  "_type": "_doc",
  "_id": "KbOj6GcBVEuCC3JSh18Y", # ES自动生成的文档的id
  "_version": 1,
  "result": "created",
  "_shards": {
    "total": 2,
    "successful": 1,
    "failed": 0
  },
  "_seq_no": 0,
  "_primary_term": 1
}

查询单个文档

GET /baizhi/_doc/1	# 语法: GET /索引名/类型名/id
-------------------------------------------------------------------
{
  "_index": "baizhi",
  "_type": "_doc",
  "_id": "1",
  "_version": 1,
  "found": true,
  "_source": {
    "name": "zs",
    "title": "张三",
    "age": 18,
    "created": "2018-12-25"
  }
}

GET /baizhi/_doc/KbOj6GcBVEuCC3JSh18Y
--------------------------------------------------------------------
{
  "_index": "baizhi",
  "_type": "_doc",
  "_id": "KbOj6GcBVEuCC3JSh18Y",
  "_version": 1,
  "found": true,
  "_source": {
    "name": "ls",
    "title": "李四",
    "age": 28,
    "created": "2018-12-26"
  }
}

修改单个文档

PUT /baizhi/_doc/KbOj6GcBVEuCC3JSh18Y  # 语法: PUT /索引名/类型名/id
{
  "name":"lxs",
  "title":"李小四"
}
--------------------------------------------------------------------
{
  "_index": "baizhi",
  "_type": "_doc",
  "_id": "KbOj6GcBVEuCC3JSh18Y",
  "_version": 2,
  "found": true,
  "_source": {
    "name": "lxs",
    "title": "李小四"
  }
}

删除单个文档

DELETE /baizhi/_doc/1	# 语法: DELETE /索引名/类型名/id

--------------------------------------------------------------------
{
  "_index": "baizhi",
  "_type": "_doc",
  "_id": "1",
  "_version": 2,
  "result": "deleted",
  "_shards": {
    "total": 2,
    "successful": 1,
    "failed": 0
  },
  "_seq_no": 1,
  "_primary_term": 1
}

批处理操作

除了能够索引、更新和删除单个文档外,Elasticsearch还提供了使用_bulk API批量执行上述任何操作的能力。这个功能非常重要,因为它提供了一种非常有效的机制,可以以尽可能少的网络往返尽可能快地执行多个操作

POST /baizhi/_doc/_bulk # 批量插入多个document
{"index":{}}
{"name":"ww","title":"王五","age":18,"created":"2018-12-27"}
{"index":{}}
{"name":"zl","title":"赵六","age":25,"created":"2018-12-27"}
-------------------------------------------------------------------
{
  "took": 65,
  "errors": false, # 批量插入成功
  "items": [
    {
      "index": {
        "_index": "baizhi",
        "_type": "_doc",
        "_id": "KrOP6WcBVEuCC3JS8V9K",
        "_version": 1,
        "result": "created",
        "_shards": {
          "total": 2,
          "successful": 1,
          "failed": 0
        },
        "_seq_no": 0,
        "_primary_term": 1,
        "status": 201
      }
    },
    {
      "index": {
        "_index": "baizhi",
        "_type": "_doc",
        "_id": "K7OP6WcBVEuCC3JS8V9K",
        "_version": 1,
        "result": "created",
        "_shards": {
          "total": 2,
          "successful": 1,
          "failed": 0
        },
        "_seq_no": 0,
        "_primary_term": 1,
        "status": 201
      }
    }
  ]
}
POST /baizhi/_doc/_bulk	 # 批量操作(包含修改和删除)
{"update":{"_id":"KrOP6WcBVEuCC3JS8V9K"}}  # 修改
{"doc":{"title":"王小五"}}
{"delete":{"_id":"K7OP6WcBVEuCC3JS8V9K"}}  # 删除

http://www.niftyadmin.cn/n/552844.html

相关文章

从零学Elasticsearch系列——深入搜索(Query、Filter、Aggregation)

系列文章: 从零学Elasticsearch系列——基础概念从零学Elasticsearch系列——环境搭建从零学Elasticsearch系列——使用kibana实现ES基本的操作从零学Elasticsearch系列——深入搜索(Query、Filter、Aggregation)从零学Elasticsearch系列——…

从零学Elasticsearch系列——集成中文分词器IK

系列文章: 从零学Elasticsearch系列——基础概念从零学Elasticsearch系列——环境搭建从零学Elasticsearch系列——使用kibana实现ES基本的操作从零学Elasticsearch系列——深入搜索(Query、Filter、Aggregation)从零学Elasticsearch系列——…

公式推导【BACF//ICCV2017】

HK Galoogahi, A Fagg, S Lucey. Learning Background-Aware Correlation Filters for Visual Tracking[C]. //ICCV2017. 一、论文中公式4的推导: 这里我关于g^{hat}的描述是有问题的。 如果我们先定义g[g1^T,g2^T,... ,gK^T]^T 那么就有g^{hat}sqrt(KT)Fg 但是作者…

从零学Elasticsearch系列——构建ES集群

系列文章: 从零学Elasticsearch系列——基础概念从零学Elasticsearch系列——环境搭建从零学Elasticsearch系列——使用kibana实现ES基本的操作从零学Elasticsearch系列——深入搜索(Query、Filter、Aggregation)从零学Elasticsearch系列——…

链表队列

import java.util.Iterator; /*** ClassName LinkedQueue* Author wangyudi* Date 2019/7/20 13:47* Version 1.0* Description* 链表是实现队列 FIFO* 成员变量:队头引用 first、队尾引用 last、大小 count、节点内部类 Node* 私有方法:* 公开方法&…

从零学Elasticsearch系列——搭建ELK Nginx日志分析平台

系列文章: 从零学Elasticsearch系列——基础概念从零学Elasticsearch系列——环境搭建从零学Elasticsearch系列——使用kibana实现ES基本的操作从零学Elasticsearch系列——深入搜索(Query、Filter、Aggregation)从零学Elasticsearch系列——…

nginx的简单使用 -- 安装与配置

curl 127.0.0.1 查看本地服务器是否启动 查看的是本地nginx/html/index.html页面 大致过程:用测试页面替换掉nginx的首页来查看nginx是否配置成功,测试成功之后更新nginx的配置文件 启动nginx /usr/local/nginx/sbin/nginx -c 查看nginx是否启动&#xf…

基于CAS实现单点登录

CAS 注:环境搭建相关资料:https://download.csdn.net/download/qq_31871785/11078868 一、概述 CAS是中央认证服务Central Authentication Service的简称。最初由耶鲁大学的Shawn Bayern 开发,后由Jasig社区维护,经过十多年发…