【数据库-ES】ES基本操作

参考:https://www.cnblogs.com/sxdcgaq8080/p/11118947.html

1.curl http://172.16.18.17:9200

{
  "name" : "node-1",
  "cluster_name" : "my-application",
  "cluster_uuid" : "9_YY1EoaR265QvxCeDkHPQ",
  "version" : {
    "number" : "7.6.2",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "ef48eb35cf30adf4db14086e8aabd07ef6fb113f",
    "build_date" : "2020-03-26T06:34:37.794943Z",
    "build_snapshot" : false,
    "lucene_version" : "8.4.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

2.curl http://172.16.18.17:9200/_cat

_cat:列出es命令参数

=^.^=
/_cat/allocation
/_cat/shards
/_cat/shards/{index}
/_cat/master
/_cat/nodes
/_cat/tasks
/_cat/indices
/_cat/indices/{index}
/_cat/segments
/_cat/segments/{index}
/_cat/count
/_cat/count/{index}
/_cat/recovery
/_cat/recovery/{index}
/_cat/health
/_cat/pending_tasks
/_cat/aliases
/_cat/aliases/{alias}
/_cat/thread_pool
/_cat/thread_pool/{thread_pools}
/_cat/plugins
/_cat/fielddata
/_cat/fielddata/{fields}
/_cat/nodeattrs
/_cat/repositories
/_cat/snapshots/{repository}
/_cat/templates

3.curl http://172.16.18.17:9200/_cat/indices?v

?v 列出查询详细结果(带属性标识)

【数据库-ES】ES基本操作

4.创建索引

curl -XPUT http://192.168.6.16:9200/my_new_index?pretty

?pretty:“pretty”来告诉Elasticsearch,做JSON格式化输出

5.插入数据

(1)错误方法

【数据库-ES】ES基本操作

此原因时由于ES增加了安全机制, 进行严格的内容类型检查,严格检查内容类型也可以作为防止跨站点请求伪造攻击的一层保护。 

 (2)解决,增加-H

curl -H "Content-Type: application/json" -XPUT http://172.16.18.17:9200/index_test/user/1?pretty -d ‘{"name":"张三","age":"23"}‘

【数据库-ES】ES基本操作

6.查询数据

curl -XGET http://172.16.18.17:9200/index_test/user/1?pretty

【数据库-ES】ES基本操作

7.更新数据

curl -XPOST http://192.168.6.16:9200/my_new_index/user/2/_update?pretty -d ‘{"doc":{"name":"李四更新","age":"230"}}

8.删除数据

curl -XDELETE http://192.168.6.16:9200/my_new_index/user/2?pretty

9.查询某个索引中的所有数据

curl -XGET http://172.16.18.17:9200/index_test/user/_search?pretty

相关推荐