Bulk 端点

  1. POST /_bulk
  2. {
  3. "delete": {
  4. "_index": "website",
  5. "_type": "blog",
  6. "_id": "123"
  7. }
  8. }

省略 type、index

  1. POST /my_store/products/_bulk
  2. {"index":{"_id":1}}
  3. {"price":10,"productID":"XHDK-A-1293-#fJ3"}
  4. {"index":{"_id":2}}
  5. {"price":20,"productID":"KDKE-B-9947-#kL5"}
  6. {"index":{"_id":3}}
  7. {"price":30,"productID":"JODL-X-1937-#pV7"}
  8. {"index":{"_id":4}}
  9. {"price":30,"productID":"QQPX-R-3956-#aD8"}

_delete_by_query, _update_by_query

必须能查询到才能更新

  1. POST /twitter/_update_by_query
  2. {
  3. "script": {
  4. "source": "ctx._source.likes++",
  5. "lang": "painless"
  6. },
  7. "query": {
  8. "term": {
  9. "user": "kimchy"
  10. }
  11. }
  12. }
  1. POST /twitter/_update_by_query
  2. {
  3. "script": {
  4. "source": "ctx._source.name = params.new_name",
  5. "params": {
  6. "new_name": "tome"
  7. },
  8. "lang": "painless"
  9. }
  10. }

script 错误示例(低版本可行):

  1. {
  2. "script": {
  3. "source": "ctx._source['xxx']='xxxxx'",
  4. "lang": "painless"
  5. }
  6. }

_update

脚本方式更新:

  1. POST /website/blog/1/_update?pretty
  2. {
  3. "script" : "ctx._source.views+=1"
  4. }

指定字段更新:

  1. POST /website/blog/1/_update?pretty
  2. {
  3. "doc" : {
  4. "tags" : ["testing"],
  5. "views": 0
  6. }
  7. }