ES常用操作备忘

格式:<REST Verb>/<Index>/<Type>/<ID>

集群健康:
curl -u lases:1fw@2soc#3vpn -XGET 'localhost:9200/_cat/health?v&pretty'

节点:
curl -u lases:1fw@2soc#3vpn -XGET 'localhost:9200/_cat/nodes?v&pretty'
查看索引:
curl -u lases:1fw@2soc#3vpn -XGET 'localhost:9200/_cat/indices?v&pretty'
创建:
curl -u lases:1fw@2soc#3vpn -XPUT 'localhost:9200/customer?pretty&pretty'
搜索:
curl -u lases:1fw@2soc#3vpn -XGET 'localhost:9200/index/report/1?pretty&pretty'
删除:
curl -u lases:1fw@2soc#3vpn -XDELETE 'localhost:9200/customer?pretty&pretty'

节点磁盘使用:
curl -u lases:1fw@2soc#3vpn -XGET 'localhost:9200/_cat/allocation?v'
插件:
curl -u lases:1fw@2soc#3vpn -XGET 'localhost:9200/_cat/plugins?v&s=component&h=name,component,version,description'

bulk api:
插入:curl -XPOST 'localhost:9200/customer/external/_bulk?pretty&pretty' -d'
{"index":{"_id":"1"}}
{"name": "John Doe" }
{"index":{"_id":"2"}}
{"name": "Jane Doe" }
更新+删除:curl -XPOST 'localhost:9200/customer/external/_bulk?pretty&pretty' -d'
{"update":{"_id":"1"}}
{"doc": { "name": "John Doe becomes Jane Doe" } }
{"delete":{"_id":"2"}}

 

导入:
curl -XPOST 'localhost:9200/bank/account/_bulk?pretty&refresh' --data-binary "@accounts.json"

搜索:
curl -XGET 'localhost:9200/bank/_search?pretty' -d'
{
"query": { "match_all": {} },
"sort": [
{ "account_number": "asc" }
],
"from": 10,
"size": 1
"_source": ["account_number", "balance"]
}'

 

bool查询:
{
"query": {
"bool": {
"must": [ //should,must_not
{ "match": { "address": "mill" } },
{ "match": { "address": "lane" } }
],
"filter": {
"range": {
"balance": {
"gte": 20000,
"lte": 30000
}
}
}
}
}
}

 

聚合:
{
"size": 0,
"aggs": {
"group_by_state": {
"terms": {
"field": "state.keyword"
}
}
}
}

 

跨集群搜索:
curl -X POST "localhost:9200/cluster_one:skyeye-las_event-2018.09.11/sim/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": {
"match_all": {}
}
}

跨集群参数配置:

curl -k -u lases:1fw@2soc#3vpn -XPUT "https://localhost:9200/_cluster/settings" -H 'Content-Type: application/json' -d'
{
"persistent": {
"search": {
"remote": {
"cluster_one": {
"seeds": [
"10.95.36.30:9300"
]
}
}
}
}
}'

 

 

插件安装:

sh elasticsearch-plugin install -b file:///home/es/search-guard-5-5.6.10-19.2.zip

sgadmin.sh -cn es -h 127.0.0.1 -cd /home/es/root/plugins/search-guard-5/sgconfig -ks /home/es/root/plugins/search-guard-5/sgconfig/es-keystore.jks -kspass 1fw@2soc#3vpn -ts /home/es/root/plugins/search-guard-5/sgconfig/truststore.jks -tspass 1fw@2soc#3vpn -nhnv

sh sgadmin.sh -cn es -h 127.0.0.1 --accept-red-cluster -cd /home/es/root/plugins/search-guard-5/sgconfig -ks /home/es/root/plugins/search-guard-5/sgconfig/es-keystore.jks -kspass 1fw@2soc#3vpn -ts /home/es/root/plugins/search-guard-5/sgconfig/truststore.jks -tspass 1fw@2soc#3vpn -nhnv

posted @ 2018-10-26 14:15  _fred  阅读(505)  评论(0编辑  收藏  举报