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
        }
      }
    ]
  }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章