es增删改查

1 增(手动设置id)

curl -XPUT http://10.202.4.93:9200/homepage/homepage/zkw:123:1 -d '
{"idCode":"zkw:123:1","consignedDate":1499673466286,"groupCode":"zkw","receCnt":1000}'

结果:

{
  "_index" : "homepage",
  "_type" : "homepage",
  "_id" : "zkw:123:1",
  "_version" : 5,
  "result" : "created",
  "_shards" : {
    "total" : 2,
    "successful" : 2,
    "failed" : 0
  },
  "created" : true
}

2 删

a 根据id删除:curl -XDELETE http://10.202.4.93:9200/homepage/homepage/zkw:123:1?pretty

结果:{
  "found" : true,
  "_index" : "homepage",
  "_type" : "homepage",
  "_id" : "zkw:123:1",
  "_version" : 2,
  "result" : "deleted",
  "_shards" : {
    "total" : 2,
    "successful" : 2,
    "failed" : 0
  }
}

b 根据条件删除:curl -XPOST http://10.202.4.93:9200/homepage/homepage/_delete_by_query?pretty -d '
{"query":{"match":{"idCode":"zkw:123:1"}}}'

结果:{
  "took" : 42,
  "timed_out" : false,
  "total" : 1,
  "deleted" : 1,
  "batches" : 1,
  "version_conflicts" : 0,
  "noops" : 0,
  "retries" : {
    "bulk" : 0,
    "search" : 0
  },
  "throttled_millis" : 0,
  "requests_per_second" : -1.0,
  "throttled_until_millis" : 0,
  "failures" : [ ]
}

3 改

a 根据id修改部分field的值:curl -XPOST http://10.202.4.93:9200/homepage/homepage/zkw:123:1/_update?pretty -d '
{"doc":{"groupCode":"zkwGroup"}}'

结果:{
  "_index" : "homepage",
  "_type" : "homepage",
  "_id" : "zkw:123:1",
  "_version" : 2,
  "result" : "updated",
  "_shards" : {
    "total" : 2,
    "successful" : 2,
    "failed" : 0
  }
}

b 根据条件批量修改:curl -XPOST http://10.202.4.93:9200/homepage/homepage/_update_by_query?pretty -d '
{"query":{"match":{"idCode":"zkw:123:1"}},"script":{"inline":"ctx._source.groupCode='12345'"}}'

结果:{
  "took" : 63,
  "timed_out" : false,
  "total" : 1,
  "updated" : 1,
  "deleted" : 0,
  "batches" : 1,
  "version_conflicts" : 0,
  "noops" : 0,
  "retries" : {
    "bulk" : 0,
    "search" : 0
  },
  "throttled_millis" : 0,
  "requests_per_second" : -1.0,
  "throttled_until_millis" : 0,
  "failures" : [ ]
}

4 查

a 根据id查找:curl -XGET http://10.202.4.93:9200/homepage/homepage/zkw:123:1?pretty

结果:{
  "_index" : "homepage",
  "_type" : "homepage",
  "_id" : "zkw:123:1",
  "_version" : 4,
  "found" : true,
  "_source" : {
    "receCnt" : 1000,
    "idCode" : "zkw:123:1",
    "consignedDate" : 1499673466286,
    "groupCode" : 123
  }
}

b 根据条件查找:curl -XGET http://10.202.4.93:9200/homepage/homepage/_search?pretty -d '
{"query":{"bool":{"must":[{"match":{"groupCode":"123"}}]}}}'

结果:

{
  "took" : 3,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 1,
    "max_score" : 9.8570595,
    "hits" : [
      {
        "_index" : "homepage",
        "_type" : "homepage",
        "_id" : "zkw:123:1",
        "_score" : 9.8570595,
        "_source" : {
          "receCnt" : 1000,
          "idCode" : "zkw:123:1",
          "consignedDate" : 1499673466286,
          "groupCode" : 123
        }
      }
    ]
  }
}




你可能感兴趣的:(大数据开发)