欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

ElasticSearch———Kibana的命令

程序员文章站 2022-07-06 10:46:55
...

ES是开源分布式查询和分析引擎
基于Lucene
Es实时查询快,格式只支持josn,开箱即用,支持分布式

ElasticSearch mysql
index(索引库 = database(数据库
type = table(表
document( = row(行
field(字段 = column(列)

创建索引

PUT /lib/
{
  "settings":{
      "index":{
        "number_of_shards":3,
        "number_of_replicas":0
      }
  }
}

PUT lib2

查看索引库配置

GET /lib/_settings

查看索引库所有配置

GET _all/_settings

增加文档
PUT必须指定ID,POST不用,POST可以自动生成ID,

PUT /lib/user/1
{
  "first_name":"sb",
  "last_name":"niubi",
  "age":11,
  "about":"i like to collect rock albums",
  "interests":["music"]
}
POST /lib/user/
{
  "first_name":"sb22",
  "last_name":"niubi2",
  "age":11,
  "about":"i like to collect rock albums2",
  "interests":["music"]
}

查询
GET /INDEX / TYPE / (ID)

GET /lib/user/1

查询部分信息

GET /lib/user/1?_source=first_name,last_name

修改
以PUT的方式进行覆盖

PUT /lib/user/1
{
  "first_name":"fff",
  "last_name":"niubi",
  "age":11,
  "about":"i like to collect rock albums",
  "interests":["music"]
}

_update修改

POST /lib/user/1/_update
{
  "doc":{
    "first_name":"modify_post"
  }
}

删除文档

DELETE /lib/user/1

删除索引

DELETE lib2

批量获取多个文档

Get /_mget
{
  "docs":[
    {
      "_index":"lib",
      "_type":"user",
      "_id":1
    },
    {
      "_index":"lib",
      "_type":"user",
      "_id":2
    },
    {
      "_index":"lib",
      "_type":"user",
      "_id":3
    }
    
  ]
}
Get /_mget
{
  "docs":[
    {
      "_index":"lib",
      "_type":"user",
      "_id":2,
      "_source":"last_name"
    },
    {
      "_index":"lib",
      "_type":"user",
      "_id":3,
      "_source":["first_name","last_name"]
    }
    
  ]
}

索引类型相同

GET /lib/user/_mget
{
  "docs":[
      {
        "_id":1
      },
      {
        "_id":2
      }
    ]
}
GET /lib/user/_mget
{
  "ids":["1","2"]
}

Bulk API
语法
{action:{metadata} }
{requstbody}
批量添加

POST /lib3/books/_bulk
{"index":{"_id":1}}
{"title":"java","price":66}
{"index":{"_id":2}}
{"title":"c","price":77}
{"index":{"_id":3}}
{"title":"golang","price":88}