ES 增删改查基本操作

插入一条数据

PUT /school/student/1
{
  "name":"tom",
  "age":18,
  "from":"china",
  "tags":["black","tall"]
}

结果:

{
  "_index" : "school",
  "_type" : "student",
  "_id" : "1",
  "_version" : 1,
  "result" : "created",
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "_seq_no" : 0,
  "_primary_term" : 1
}

查询一条数据

GET /school/student/1

结果:

{
  "_index" : "school",
  "_type" : "student",
  "_id" : "1",
  "_version" : 1,
  "_seq_no" : 0,
  "_primary_term" : 1,
  "found" : true,
  "_source" : {
    "name" : "tom",
    "age" : 18,
    "from" : "china",
    "tags" : [
      "black",
      "tall"
    ]
  }
}

查询所有数据

GET /school/student/_search 
{
  "query": {
    "match_all": {}
  }
}

结果:

{
  "took" : 5,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "school",
        "_type" : "student",
        "_id" : "1",
        "_score" : 1.0,
        "_source" : {
          "name" : "tom",
          "age" : 18,
          "from" : "china",
          "tags" : [
            "black",
            "tall"
          ]
        }
      }
    ]
  }
}

查询特定属性

GET /school/student/_search 
{
  "query": {
    "match_all": {}
  },
  "_source": ["name","age"]
}

结果:

{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "school",
        "_type" : "student",
        "_id" : "1",
        "_score" : 1.0,
        "_source" : {
          "name" : "tom",
          "age" : 18
        }
      }
    ]
  }
}
上一篇:MySQL 日志管理、备份与恢复


下一篇:开发笔记