Elasticsearch5.6中常用curl命令
1.查看集群状态
curl --location --request GET 'http://ip:port/_cluster/health?pretty'
2.查看节点状态
curl --location --request GET 'http://ip:port/_cat/nodes?pretty'
3.查看分片状态
curl --location --request GET 'http://ip:port/_cat/shards?pretty'
4.查看索引列表
curl --location --request GET 'http://ip:port/_cat/indices'
5.查看索引详细信息
curl --location --request GET 'http://ip:port/newgroupuser/_stats?pretty'
6.查看指定索引的文档数量
curl --location --request GET 'http://ip:port/indexName/_mapping'
7.查看指定索引mapping
curl --location --request GET 'http://ip:port/indexName/_mapping?pretty'
8.查看指定索引的settings
curl --location --request GET 'http://ip:port/indexName/_settings?pretty'
9.查询数据
curl --location --request GET 'http://ip:port/indexName/_search?pretty'
10.通过文档id查询数据
curl --location --request GET 'http://ip:port/indexName/doc/c2b157e5-d466-4bb3-9c10-99cba8c513c9_ext'
11.搜索群组
curl --location --request GET 'http://ip:port/indexName/_search?pretty' \
--header 'Content-Type: application/json' \
-d '{
"query": {
"bool": {
"must": [
{
"term": {
"id": "5cd3e46be4b04cd13b217f00"
}
}
]
}
}
}'
12.索引新增字段
curl --location --request PUT 'http://ip:port/indexName/_mapping/doc' \
--header 'Content-Type: application/json' \
--data-raw '{
"properties":{
"id": {
"index": true,
"store": true,
"type": "keyword"
},
"userName": {
"index": true,
"store": true,
"type": "keyword"
}
}
}'
13.查看索引模板
curl --location --request GET 'http://ip:port/_template'
14.es迁移数据
curl --location --request POST 'http://ip:port/_reindex?pretty' \
--header 'Authorization: Basic ZWxhc3RpYzpsam0wMTE3MzIzMQ==' \
--header 'Content-Type: application/json' \
--data-raw '{
"conflicts": "proceed",
"source": {
"remote": {
"host": "http://ip:port/"
},
"index": "indexName",
"query": {
"term": {
"_type": "doc"
}
},
"size": 10000,
"slice":{
"id":0,
"max":5
}
},
"dest": {
"index": "indexName"
},
"script": {
"inline": "if (ctx._id.length()>512) {ctx._id = ctx._id.substring(0,511)}",
"lang": "painless"
}
}'
15.ealsticsearch关闭索引操作
curl --location --request POST 'http://ip:port/indexNametest/_close'
16.elasticsearch打开索引操作
curl --location --request POST 'http://ip:port/indexNametest/_open'
17.elasticsearch动态修改setting中的分词器
curl --location --request PUT 'http://ip:port/indexName/_settings' \
--header 'Content-Type: application/json' \
-d'{
"analysis": {
"analyzer":{
"full_pinyin_analyzer":{
"filter":[ "lc_full_pinyin"],
"tokenizer":"keyword",
"type":"custom"
}
}
}
}'
20.elasticsearch动态添加指定字段mapping
curl --location --request PUT 'http://ip:port/indexName/_mapping/doc' \
--header 'Content-Type: application/json' \
-d '{
"properties": {
"userNameFullPinyin": {
"index": true,
"store": true,
"type": "text",
"analyzer": "full_pinyin_analyzer"
}
}
}'