kibana操作

number_of_shards 分片
number_of_replicas备份份数

PUT /lib/   #lib为索引,这里创建一个索引
{
  "settings": {
    "index":{
      "number_of_shards":5,
      "number_of_replicas": 1
    }
  }
}
运行结果:
{
  "acknowledged" : true,
  "shards_acknowledged" : true,
  "index" : "lib"
}

GET /lib
{
  "lib" : {
    "aliases" : { },
    "mappings" : { },
    "settings" : {
      "index" : {
        "creation_date" : "1554167098772",
        "number_of_shards" : "5",
        "number_of_replicas" : "1",
        "uuid" : "ZEo4nxKuRHCmM21Jk5Ip2w",
        "version" : {
          "created" : "6070099"
        },
        "provided_name" : "lib"
      }
    }
  }
}

GET /lib/_settings
{
  "lib" : {
    "settings" : {
      "index" : {
        "creation_date" : "1554167098772",
        "number_of_shards" : "5",
        "number_of_replicas" : "1",
        "uuid" : "ZEo4nxKuRHCmM21Jk5Ip2w",
        "version" : {
          "created" : "6070099"
        },
        "provided_name" : "lib"    //索引
      }
    }
  }
}

 

PUT /lib2
{
  "acknowledged" : true,
  "shards_acknowledged" : true,
  "index" : "lib2"
}

GET /lib2
{
  "lib2" : {
    "aliases" : { },
    "mappings" : { },
    "settings" : {
      "index" : {
        "creation_date" : "1554167422942",
        "number_of_shards" : "5",
        "number_of_replicas" : "1",
        "uuid" : "BaN-ijHYQJeRvc0PE2o08w",
        "version" : {
          "created" : "6070099"
        },
        "provided_name" : "lib2"
      }
    }
  }
}

GET /_all/_settings
......
DELETE /lib/        //删除索引
{
  "acknowledged" : true
}

 

指定id用put 不指定id用post
POST /lib/user/
{
  "first_name": "Cao",
  "last_name": "min",
  "age": 23
}

{
  "_index" : "lib",
  "_type" : "user",
  "_id" : "9WCv22kB5eS_NzcvF_kl",
  "_version" : 1,
  "result" : "created",
  "_shards" : {
    "total" : 2,
    "successful" : 2,
    "failed" : 0
  },
  "_seq_no" : 0,
  "_primary_term" : 1
}
查询文档
GET /lib/user/9WCv22kB5eS_NzcvF_kl
{
  "_index" : "lib",
  "_type" : "user",
  "_id" : "9WCv22kB5eS_NzcvF_kl",
  "_version" : 1,
  "_seq_no" : 0,
  "_primary_term" : 1,
  "found" : true,
  "_source" : {
    "first_name" : "Cao",
    "last_name" : "min",
    "age" : 23
  }
}
查看id为9WCv22kB5eS_NzcvF_kl的first_name和age
GET /lib/user/9WCv22kB5eS_NzcvF_kl?_source=first_name,age
{
  "_index" : "lib",
  "_type" : "user",
  "_id" : "9WCv22kB5eS_NzcvF_kl",
  "_version" : 1,
  "_seq_no" : 0,
  "_primary_term" : 1,
  "found" : true,
  "_source" : {
    "first_name" : "Cao",
    "age" : 23
  }
}

更新文档

索引:lib
类型:user
id: 9WCv22kB5eS_NzcvF_kl

id相同的覆盖
使用覆盖方式更新(未覆盖的数据会丢失)
PUT /lib/user/9WCv22kB5eS_NzcvF_kl
{
  "age" : 30
}
{
  "_index" : "lib",
  "_type" : "user",
  "_id" : "9WCv22kB5eS_NzcvF_kl",
  "_version" : 2,
  "result" : "updated",
  "_shards" : {
    "total" : 2,
    "successful" : 2,
    "failed" : 0
  },
  "_seq_no" : 1,
  "_primary_term" : 1
}
GET /lib/user/9WCv22kB5eS_NzcvF_kl
{
  "_index" : "lib",
  "_type" : "user",
  "_id" : "9WCv22kB5eS_NzcvF_kl",
  "_version" : 2,
  "_seq_no" : 1,
  "_primary_term" : 1,
  "found" : true,
  "_source" : {
    "age" : 30
  }
}

post方式更新(未指定的原有数据不会丢失)
POST /lib/user/9WCv22kB5eS_NzcvF_kl/_update
{
  "doc": {
    "sex": "female"
  }
}
{
  "_index" : "lib",
  "_type" : "user",
  "_id" : "9WCv22kB5eS_NzcvF_kl",
  "_version" : 6,
  "result" : "updated",
  "_shards" : {
    "total" : 2,
    "successful" : 2,
    "failed" : 0
  },
  "_seq_no" : 5,
  "_primary_term" : 1
}
GET /lib/user/9WCv22kB5eS_NzcvF_kl
{
  "_index" : "lib",
  "_type" : "user",
  "_id" : "9WCv22kB5eS_NzcvF_kl",
  "_version" : 6,
  "_seq_no" : 5,
  "_primary_term" : 1,
  "found" : true,
  "_source" : {
    "age" : 28,
    "sex" : "female"
  }
}

获得所有信息
GET /_all/_settings

Multi-Get批量查询:

PUT /index/a/1
{
  "name": "ZhangSan",
  "age": 18
}

PUT /index/a/3
{
  "name": "LiSi",
  "age": 20
}

//使用mget通过索引类型和id获取相关信息
GET /_mget  //这里获得了2个文档
{
  "docs":[
    {
      "_index": "index",
      "_type": "a",
      "_id": "1"
    },
    {
      "_index": "index",
      "_type": "a",
      "_id": "3"
    }
  ]
}
获得指定的字段
第一个只获取name字段,第二个只获取name、age字段
GET /_mget
{
  "docs":[
    {
      "_index": "index",
      "_type": "a",
      "_id": "1",
      "_source":"name"  
    },
    {
      "_index": "index",
      "_type": "a",
      "_id": "3",
      "_source":["name", "age"]
    }
  ]
}
或者简化写法
GET /index/a/_mget
{
  "docs":[
    {
      
      "_id": "1",
      "_source":"name"  
    },
    {
      "_id": "3",
      "_source":["name", "age"]
    }
  ]
}
或者
GET /index/a/_mget
{
  "ids":["1", "3"]
}

结果:
{
  "docs" : [
    {
      "_index" : "index",
      "_type" : "a",
      "_id" : "1",
      "_version" : 1,
      "_seq_no" : 0,
      "_primary_term" : 1,
      "found" : true,
      "_source" : {
        "name" : "ZhangSan"
      }
    },
    {
      "_index" : "index",
      "_type" : "a",
      "_id" : "3",
      "_version" : 1,
      "_seq_no" : 0,
      "_primary_term" : 1,
      "found" : true,
      "_source" : {
        "name" : "LiSi",
        "age" : 20
      }
    }
  ]
}

 

posted @ 2019-04-02 09:59  牧 天  阅读(305)  评论(0)    收藏  举报