es on kibana 实操

教程 犀牛 ⋅ 于 2021-06-05 11:14:27 ⋅ 1507 阅读

集群操作

  • 查看集群健康情况
GET /_cat/health?v

file

  • 查看索引状态
GET /_cat/indices?v

file

索引操作

  • 创建索引
put /xiniu1

file

file

  • 删除索引
delete /xiniu1

file

file

  • 创建索引并制定mapping映射
PUT /xiniu
{
  "mappings": {
    "properties": { 
      "title":    { "type": "text"  }, 
      "name":     { "type": "text"  }, 
      "age":      { "type": "integer" },  
      "created":  {
        "type":   "date", 
        "format": "strict_date_optional_time||epoch_millis"
      }
    }
  }
}

file

  • 查看mapping
GET /xiniu/_mapping

file

  • 插入数据
# 不指定id
POST /xiniu/_doc
{
  "name":"ls",
  "title":"李四",
  "age":28,
  "created":"2021-06-04"
}

file

# 指定id插入
POST /xiniu/_doc/1
{
  "name":"ls",
  "title":"李四",
  "age":28,
  "created":"2021-06-04"
}

file

  • 查询文档
GET /xiniu/_doc/1

file

  • 修改文档内容
PUT /xiniu/_doc/1
{
  "name":"lls",
  "title":"李老四"
}

file

file

  • 删除文档内容
delete /xiniu/_doc/1

file

  • 批量插入
# 使用_bulk方式批量插入
POST /xiniu/_doc/_bulk
{"index":{}}
{"name":"zhaoy","title":"赵杨","age":18,"created":"2021-06-05"}
{"index":{}}
{"name":"yux","title":"宇鑫","age":25,"created":"2021-06-05"}

file

搜索篇

  • 批量插入(指定id)
# 批量插入测试数据
POST /hainiu/user/_bulk
{"index":{"_id":1}}
{"name":"laoli","realname":"老李","age":28,"birthday":"2012-11-17","salary":20000.0,"address":"北京市昌平区"}
{"index":{"_id":2}}
{"name":"laozhang","realname":"老张","age":20,"birthday":"2012-12-21","salary":2000.0,"address":"北京市朝阳区"}
{"index":{"_id":3}}
{"name":"laowang","realname":"老王","age":25,"birthday":"2015-06-16","salary":3300.0,"address":"北京市海淀区"}
{"index":{"_id":4}}
{"name":"laosun","realname":"老孙","age":20,"birthday":"2006-06-16","salary":15300.0,"address":"北京市海淀区中关村软件园"}
{"index":{"_id":5}}
{"name":"laozhao","realname":"老赵","age":35,"birthday":"2011-06-16","salary":1303.0,"address":"北京市海淀区西二旗"}

file

  • 查询所有数据并排序
GET /hainiu/user/_search
{
  "query":{
    "match_all": {}
  },
  "sort":{
    "age":"desc"
  }
}

file

  • 分页查询
GET /hainiu/user/_search
{
  "query":{
    "match_all": {}
  },
  "sort":{
    "age":"desc"
  },
  "from":0,
  "size":2
}

file

  • 匹配查询
GET /hainiu/user/_search
{
  "query":{
    "match": {
      "birthday": "2015-06-16"
    }
  }
}

file

  • 精确查询
GET /hainiu/user/_search
{
  "query":{
    "term": {
      "name": {
        "value": "laoli"
      }
    }
  }
}

file

  • 范围查询
GET /hainiu/user/_search
{
  "query":{
    "range": {
      "age": {
        "gte": 15,
        "lte": 24
      }
    }
  }
}

file

版权声明:原创作品,允许转载,转载时务必以超链接的形式表明出处和作者信息。否则将追究法律责任。来自海汼部落-犀牛,http://hainiubl.com/topics/75640
回复数量: 0
    暂无评论~~
    • 请注意单词拼写,以及中英文排版,参考此页
    • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`, 更多语法请见这里 Markdown 语法
    • 支持表情,可用Emoji的自动补全, 在输入的时候只需要 ":" 就可以自动提示了 :metal: :point_right: 表情列表 :star: :sparkles:
    • 上传图片, 支持拖拽和剪切板黏贴上传, 格式限制 - jpg, png, gif,教程
    • 发布框支持本地存储功能,会在内容变更时保存,「提交」按钮点击时清空
    Ctrl+Enter