一 新增文档

  1. #新增一个id为1的书籍(POST和PUT都可以)
  2. POST lqz/_doc/1/_create
  3. #POST lqz/_doc/1
  4. #POST lqz/_doc 会自动创建id,必须用Post
  5. {
  6. "title":"红楼梦",
  7. "price":12,
  8. "publish_addr":{
  9. "province":"黑龙江",
  10. "city":"鹤岗"
  11. },
  12. "publish_date":"2013-11-11",
  13. "read_num":199,
  14. "tag":["古典","名著"]
  15. }

二 查询文档

  1. #查询lqz索引下id为7的文档
  2. GET lqz/_doc/7
  3. #查询lqz索引下id为7的文档,只要title字段
  4. GET lqz/_doc/7?_source=title
  5. #查询lqz索引下id为7的文档,只要title和price字段
  6. GET lqz/_doc/7?_source=title,price
  7. #查询lqz索引下id为7的文档,要全部字段
  8. GET lqz/_doc/7?_source

三 修改文档

  1. #修改文档(覆盖修改)
  2. PUT lqz/_doc/10
  3. {
  4. "title":"xxxx",
  5. "price":333,
  6. "publish_addr":{
  7. "province":"黑龙江",
  8. "city":"福州"
  9. }
  10. }
  11. #修改文档,增量修改,只修改某个字段(注意是post)
  12. POST lqz/_update/10
  13. {
  14. "doc":{
  15. "title":"修改"
  16. }
  17. }

四 删除文档

  1. #删除文档id为10的
  2. DELETE lqz/_doc/10

五 批量操作之_mget

  1. #批量获取lqz索引_doc类型下id为2的数据和lqz2索引_doc类型下id为1的数据
  2. GET _mget
  3. {
  4. "docs":[
  5. {
  6. "_index":"lqz",
  7. "_type":"_doc",
  8. "_id":2
  9. },
  10. {
  11. "_index":"lqz2",
  12. "_type":"_doc",
  13. "_id":1
  14. }
  15. ]
  16. }
  17. #批量获取lqz索引下id为1和2的数据
  18. GET lqz/_mget
  19. {
  20. "docs":[
  21. {
  22. "_id":2
  23. },
  24. {
  25. "_id":1
  26. }
  27. ]
  28. }
  29. #同上
  30. GET lqz/_mget
  31. {
  32. "ids":[1,2]
  33. }

六 批量操作之 bulk

  1. PUT test/_doc/2/_create
  2. {
  3. "field1" : "value22"
  4. }
  5. POST _bulk
  6. { "index" : { "_index" : "test", "_id" : "1" } }
  7. { "field1" : "value1" }
  8. { "delete" : { "_index" : "test", "_id" : "2" } }
  9. { "create" : { "_index" : "test", "_id" : "3" } }
  10. { "field1" : "value3" }
  11. { "update" : {"_id" : "1", "_index" : "test"} }
  12. { "doc" : {"field2" : "value2"} }