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