学习用Node.js和Elasticsearch构建搜索引擎(3):使用curl命令操作elasticsearch
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了学习用Node.js和Elasticsearch构建搜索引擎(3):使用curl命令操作elasticsearch,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3686字,纯文字阅读大概需要6分钟。
内容图文
使用Elasticsearch不免要提到curl工具,curl是利用URL语法在命令行方式下工作的开源文件传输工具。官网地址:https://curl.haxx.se/
因为elasticsearch提供了标准的http接口,所以我们可以使用curl方便的访问elasticsearch。
下面收集了一些使用curl命令操作elasticsearch。
第一:_cat系列
_cat系列提供了一系列查询elasticsearch集群状态的接口。你可以通过执行
curl -XGET localhost:9200/_cat 获取所有_cat系列的操作
$ curl -XGET localhost:9200/_cat =^.^= /_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
第二:_cluster系列
1、查询设置集群状态
curl -XGET localhost:9200/_cluster/health?pretty=true pretty=true表示格式化输出 level=indices 表示显示索引状态 level=shards 表示显示分片信息
2、显示集群系统信息,包括CPU、JVM等等
curl -XGET localhost:9200/_cluster/stats?pretty=true
3、 显示集群的详细信息,包括节点、分片等。
curl -XGET localhost:9200/_cluster/state?pretty=true
4、获取集群堆积的任务。
curl -XGET localhost:9200/_cluster/pending_tasks?pretty=true
5、修改集群配置
举例:
curl -XPUT localhost:9200/_cluster/settings -d '{ "persistent" : { "discovery.zen.minimum_master_nodes" : 2 } }'
transient 表示临时的,persistent表示永久的
6、对shard的手动控制
curl -XPOST ‘localhost:9200/_cluster/reroute’ -d ‘xxxxxx’
参考http://zhaoyanblog.com/archives/687.html
7、关闭节点
例如:关闭指定192.168.1.1节点
curl -XPOST 'http://192.168.1.1:9200/_cluster/nodes/_local/_shutdown' curl -XPOST 'http://localhost:9200/_cluster/nodes/192.168.1.1/_shutdown'
关闭主节点
curl -XPOST 'http://localhost:9200/_cluster/nodes/_master/_shutdown'
关闭整个集群
$ curl -XPOST 'http://localhost:9200/_shutdown?delay=10s' $ curl -XPOST 'http://localhost:9200/_cluster/nodes/_shutdown' $ curl -XPOST 'http://localhost:9200/_cluster/nodes/_all/_shutdown' delay=10s表示延迟10秒关闭
第三:_nodes系列
1、查询节点的状态
curl -XGET 'http://localhost:9200/_nodes/stats?pretty=true' curl -XGET 'http://localhost:9200/_nodes/192.168.1.2/stats?pretty=true' curl -XGET 'http://localhost:9200/_nodes/process' curl -XGET 'http://localhost:9200/_nodes/_all/process' curl -XGET 'http://localhost:9200/_nodes/192.168.1.2,192.168.1.3/jvm,process' curl -XGET 'http://localhost:9200/_nodes/192.168.1.2,192.168.1.3/info/jvm,process' curl -XGET 'http://localhost:9200/_nodes/192.168.1.2,192.168.1.3/_all' curl -XGET 'http://localhost:9200/_nodes/hot_threads'
第四:索引操作
1、获取索引
curl -XGET 'http://localhost:9200/{index}/{type}/{id}'
2、索引数据
curl -XPOST 'http://localhost:9200/{index}/{type}/{id}’ -d'{“a”:”avalue”,”b”:”bvalue”}'
3、删除索引
curl -XDELETE 'http://localhost:9200/{index}/{type}/{id}'
4、设置mapping
curl -XPUT http://localhost:9200/{index}/{type}/_mapping -d '{ "{type}" : { "properties" : { "date" : { "type" : "long" }, "name" : { "type" : "string", "index" : "not_analyzed" }, "status" : { "type" : "integer" }, "type" : { "type" : "integer" } } } }'
5、获取mapping
curl -XGET http://localhost:9200/{index}/{type}/_mapping
6、搜索
curl -XGET 'http://localhost:9200/{index}/{type}/_search' -d '{ "query" : { "term" : { "user" : "kimchy" } //查所有 "match_all": {} }, "sort" : [{ "age" : {"order" : "asc"}},{ "name" : "desc" } ], "from":0, "size":100 } curl -XGET 'http://localhost:9200/{index}/{type}/_search' -d '{ "filter": {"and":{"filters":[{"term":{"age":"123"}},{"term":{"name":"张三"}}]}, "sort" : [{ "age" : {"order" : "asc"}},{ "name" : "desc" } ], "from":0, "size":100 }
参考原创链接地址:http://zhaoyanblog.com/archives/732.html
内容总结
以上是互联网集市为您收集整理的学习用Node.js和Elasticsearch构建搜索引擎(3):使用curl命令操作elasticsearch全部内容,希望文章能够帮你解决学习用Node.js和Elasticsearch构建搜索引擎(3):使用curl命令操作elasticsearch所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。