当前位置:   article > 正文

ES-命令_es xget获取全部数据

es xget获取全部数据

节点

  1. #查看节点信息
  2. curl -XGET 'http://127.0.0.1:9200/_cat/nodes?v'
  3. #查看所有节点信息
  4. curl -XGET 'http://127.0.0.1:9200/_nodes?pretty=true'
  5. #查看指定节点的信息
  6. curl -XGET 'http://127.0.0.1:9200/_nodes/nodeName?pretty=true'

索引

  1. #查看所有索引
  2. curl -XGET 'http://localhost:9200/_cat/indices?v'
  3. #创建索引
  4. curl -XPUT "http://localhost:9200/test_index"
  5. #创建索引,指定分片和副本的数量
  6. curl -H "Content-Type: application/json" -XPUT "http://localhost:9200/test_index?pretty" -d'
  7. {
  8. "settings": {
  9. "number_of_shards": 2,
  10. "number_of_replicas": 1
  11. }
  12. }'
  13. #创建索引(test_index)、创建类型(product)、指定mapping的数据
  14. curl -H "Content-Type: application/json" -XPUT "http://localhost:9200/test_index?pretty" -d'
  15. {
  16. "mappings": {
  17. "product" : {
  18. "properties": {
  19. "id" : {
  20. "type": "text",
  21. "index": "false"
  22. },
  23. "userName" : {
  24. "type": "text",
  25. "index": "true"
  26. }
  27. }
  28. }
  29. }
  30. }'
  31. #在已创建的索引下添加类型的mapping
  32. curl -H "Content-Type: application/json" -XPUT 'http://localhost:9200/test_index/person/_mapping?pretty' -d '{
  33. "person" : {
  34. "properties" : {
  35. "date" : {
  36. "type" : "long"
  37. },
  38. "name" : {
  39. "type" : "text",
  40. "index" : "false"
  41. },
  42. "status" : {
  43. "type" : "integer"
  44. },
  45. "type" : {
  46. "type" : "integer"
  47. }
  48. }
  49. }
  50. }'
  51. #获取索引信息
  52. curl -XGET "http://localhost:9200/test_index?pretty"
  53. #查看索引的统计信息
  54. curl -XGET "http://localhost:9200/test_index/_stats?pretty"
  55. #获取索引的mappings
  56. curl -XGET "http://localhost:9200/test_index/_mappings?pretty"
  57. #删除索引
  58. curl -XDELETE "http://localhost:9200/test_index"

文档

  1. #插入数据
  2. curl -H "Content-Type: application/json" -XPOST 'http://localhost:9200/test_index/person/?pretty' -d '{"date":11222, "name": "abc", "status": 1,"type":134}'
  3. #查询索引中的全部内容
  4. curl -XGET "http://localhost:9200/test_index/_search?pretty"
  5. #查询某个type的内容
  6. curl -XGET "http://localhost:9200/test_index/person/_search?pretty"
  7. #根据文档的id查询文档,如果需要查询多个字段使用逗号进行隔开,不指定就是显示全部字段
  8. curl -XGET "http://localhost:9200/test_index/person/zbyJjXYB2UzVbYB2ykZa?_source=name,type&pretty"
  9. #根据条件进行简单查询
  10. curl -XGET "http://localhost:9200/test_index/person/_search?q=name:&pretty"
  11. #更新文档内容
  12. curl -H "Content-Type: application/json" -XPOST 'http://localhost:9200/test_index/person/0LyYjXYB2UzVbYB2qUZi/_update?pretty' -d '{"doc":{ "name": "wxg111", "status": 1,"type":134}}'
  13. #删除文档内容
  14. curl -XDELETE "http://localhost:9200/test_index/person/zryOjXYB2UzVbYB2AkbI?&pretty"

DSL

  1. #查询索引下所有文档
  2. curl -H "Content-Type: application/json" -XPOST 'http://localhost:9200/test_index/_search?pretty' -d '{"query": { "match_all": {} }}'
  3. #查询索引下所有文档,并返回第一个文档
  4. curl -H "Content-Type: application/json" -XPOST 'http://localhost:9200/test_index/_search?pretty' -d '{"query": { "match_all": {} },"size":1}'
  5. #匹配所有并返回第1到10
  6. curl -H "Content-Type: application/json" -XPOST 'http://localhost:9200/test_index/_search?pretty' -d '{"query": { "match_all": {} },"from": 0,"size": 10}'
  7. #根据属性降序排序(size未指定默认为10)
  8. curl -H "Content-Type: application/json" -XPOST 'http://localhost:9200/test_index/_search?pretty' -d '{"query": { "match_all": {} },"sort": {"status": { "order": "desc" }}}'
  9. #返回name和status这2个fields(_source里),相当于sql:SELECT name, status FROM....
  10. curl -H "Content-Type: application/json" -XPOST 'http://localhost:9200/test_index/_search?pretty' -d '{"query": { "match_all": {} },"_source": ["name", "status"]}'
  11. #返回status为1的,相当于sql的WHERE
  12. curl -H "Content-Type: application/json" -XPOST 'http://localhost:9200/test_index/_search?pretty' -d '{"query": { "match": { "status": 1 } }}'
  13. #返回type=77 && status=1的文档
  14. curl -H "Content-Type: application/json" -XPOST 'http://localhost:9200/test_index/_search?pretty' -d '{"query": {"bool": {"must": [{ "match": { "type": 77 } },{ "match": { "status": 1 } }]}}}'
  15. #返回type=77 || status=1的文档
  16. curl -H "Content-Type: application/json" -XPOST 'http://localhost:9200/test_index/_search?pretty' -d '{"query": {"bool": {"should": [{ "match": { "type": 77 } },{ "match": { "status": 1 } }]}}}'
  17. #返回type=77 非 status=1的文档
  18. curl -H "Content-Type: application/json" -XPOST 'http://localhost:9200/test_index/_search?pretty' -d '{"query": {"bool": {"must_not": [{ "match": { "type": 77 } },{ "match": { "status": 1 } }]}}}'
  19. #返回type是134但status不是2的
  20. curl -H "Content-Type: application/json" -XPOST 'http://localhost:9200/test_index/_search?pretty' -d '{"query": {"bool": { "must": [{ "match": { "type": 134 } }],"must_not": [{ "match": { "status": 2 } }]}}}'
  21. # 相当于sql: SELECT COUNT() from bank GROUP BY state ORDER BY COUNT() DESC。
  22. #「size=0」是设置不显示search hit
  23. curl -H "Content-Type: application/json" -XPOST 'http://localhost:9200/test_index/_search?pretty' -d '{"size": 0,"aggs": {"group_by_state": {"terms": {"field": "status"}}}}'
  24. #按state分组并计算(组)平均balance(默认返回前10个按state的COUNT的降序(DESC)排)
  25. curl -H "Content-Type: application/json" -XPOST 'http://localhost:9200/test_index/_search?pretty' -d '{"size": 0,"aggs": {"group_by_state": {"terms": {"field": "status"},"aggs": {"average_balance": {"avg": {"field": "type"}}}}}}'

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/663332
推荐阅读
相关标签
  

闽ICP备14008679号