ElasticSearch常用操作命令


简介

ElasticSearch的基本概念

Index 类似于mysql数据库中的database

Type 类似于mysql数据库中的table表,es中可以在Index中建立type(table),通过mapping进行映射

Document 由于es存储的数据是文档型的,一条数据对应一篇文档即相当于mysql数据库中的一行数据row,一个文档中可以有多个字段也就是mysql数据库一行可以有多列

Field es中一个文档中对应的多个列与mysql数据库中每一列对应

Mapping 可以理解为mysql或者solr中对应的schema,只不过有些时候es中的mapping增加了动态识别功

indexed 就是名义上的建立索引

Query DSL 类似于mysql的sql语句,只不过在es中是使用的json格式的查询语句,专业术语就叫:QueryDSL GET/PUT/POST/DELETE

使用curl命令操作ElasticSearch 格式如下

curl -X<REST Verb> <Node>:<Port>/<Index>/<Type>/<ID>

  <REST Verb>:REST风格的语法谓词
  <Node>:节点ip   
  <Index>:索引名
  <Type>:索引类型
  <ID>:操作对象的ID号

_cat系列

curl -XGET  localhost:9200/_cat/health?v
​
/_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系列

# 查询集群状态,显示集群系统信息,包括CPU JVM,节点、分片,获取集群堆积的任务等。
# 设置集群配置,关闭节点,关闭集群
curl -XGET localhost:9200/_cluster/health?pretty=true


/health
/stats
/pending_tasks

/settings
/reroute
/nodes/192.168.1.1/_shutdown
/nodes/_all/_shutdown

_nodes系列

#查询节点的状态
curl -XGET 'http://localhost:9200/_nodes/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'

索引操作



#获取索引
/{index}/{type}/{id}
curl -XGET 'http://localhost:9200/{index}/{type}/{id}'
2、索引数据

3、删除索引
curl -XDELETE 'http://localhost:9200/{index}/{type}/{id}'
#索引数据
curl -XPOST 'http://localhost:9200/{index}/{type}/{id}' -d'{"a":"avalue","b":"bvalue"}'
#删除索引
curl -XDELETE 'http://localhost:9200/{index}/{type}/{id}'

#设置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"
	  }
	}
  }
}'

#获取mapping
curl -XGET 'http://localhost:9200/{index}/{type}/_mapping'

文档操作

curl -XGET 'http://localhost:9200/{index}/_mget'  -d '{
"docs":[
	 {
		"_index": "lib",
		"_type": "user",
		"_id": 1
	 },
	 {
		"_index": "lib",
		"_type": "user",
		"_id": 2
	 }
 ]
}'
...
...
...
未完待续


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM