ㅤㅤㅤ
ㅤㅤㅤ
ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ(活得快乐的最重要因素是人生有事干、有人可去爱,以及生命中有所冀望。——约瑟夫·艾迪生)
ㅤㅤㅤ
ㅤㅤㅤ
ㅤㅤㅤㅤㅤㅤㅤㅤㅤ
ElasticSearch 数据迁移方案
ElasticSearch 常用api{
“name”: “node-3”,
“cluster_name”: “test-elasticsearch”,
“cluster_uuid”: “FM6vTooBTS6cSM9scMEU7g”,
“version”: {
“number”: “2.4.1”,
“build_hash”: “c67dc32e24162035d18d6fe1e952c4cbcbe79d16”,
“build_timestamp”: “2016-09-27T18:57:55Z”,
“build_snapshot”: false,
“lucene_version”: “5.5.2”
},
“tagline”: “You Know, for Search”
}
创建索引结构获取索引结构删除索引结构创建索引文档更新索引文档删除索引文档分析检索文本获取索引结构信息获取索引结构信息mappings获取索引结构信息settings检索索引文档验证索引文档关闭索引开启索引索引迁移异步索引迁移查看异步任务取消异步任务更新索引结构settings更新索引结构mappings查看elasticsearch版本信息查看elasticsearch所有数据量查看elasticsearch某索引数据量查看elasticsearch统计信息查看指定索引的统计信息 创建es索引结构
curl --location --request POST 'http://172.21.0.31:9900/business'
--header 'Content-Type: application/json'
--data-raw '{
"settings": {
"number_of_shards": 7,
"number_of_replicas": 1,
"analysis": {
"analyzer": {
"default": {
"tokenizer": "1_25_tokenizer_grams",
"filter": [
"unique",
"limit_filter"
]
}
},
"tokenizer": {
"1_25_tokenizer_grams": {
"type": "ngram",
"min_gram": 1,
"max_gram": 25
}
},
"filter": {
"limit_filter": {
"type": "limit",
"max_token_count": 500
}
}
}
},
"mappings": {
"business": {
"properties": {
"account": {
"type": "string",
"index": "not_analyzed"
},
"number": {
"type": "string",
"index": "not_analyzed"
},
"flow": {
"type": "string",
"index": "not_analyzed"
},
"createTime": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}'
获取索引结构
curl --location --request GET 'http://172.21.0.31:9900/business_bak'删除索引结构
curl --location --request DELETE 'http://172.21.0.31:9900/business/222'
--header 'Content-Type: application/json'
--data-raw '{
"name": "zhangShang",
"age": 20,
"sex": 1
}'
创建索引文档
当不指定id时,es会自动生成id
curl --location --request POST 'http://172.21.0.31:9900/business/business'
--header 'Content-Type: application/json'
--data-raw '{
"name": "zhangShang",
"age": 20,
"sex": 1
}'
更新索引文档
后面跟着id
curl --location --request POST 'http://172.21.0.31:9900/business/business/AX9jJKe7bgbIdsKXBSG4'
--header 'Content-Type: application/json'
--data-raw '{
"name": "te222st",
"age": 20,
"sex": 1
}'
删除索引文档
curl --location --request DELETE 'http://172.21.0.31:9900/business/business/AX9jJKe7bgbIdsKXBSG4'
--header 'Content-Type: application/json'
--data-raw '{
"name": "te222st",
"age": 20,
"sex": 1
}'
分析检索文本
curl --location --request POST 'http://172.21.0.31:9900/business/_analyze'
--header 'Content-Type: application/json'
--data-raw '{
"text": "zhangzw客户123"
}'
获取索引结构信息
curl --location --request GET 'http://172.21.0.31:9900/business'获取索引结构信息mappings
curl --location --request GET 'http://172.21.0.31:9900/business/_mapping?pretty'获取索引结构信息settings
curl --location --request GET 'http://172.21.0.31:9900/business/_settings' --data-raw ''检索索引文档
curl --location --request GET 'http://172.21.0.31:9900/business/_search?explain'
--header 'Content-Type: application/json'
--data-raw '{
"query": {
"bool": {
"should": [
{
"term": {
"def45310-019d-11ec-8372-1f0ef8ecd3d5": "zw3"
}
}
],
"filter": [
{
"term": {
"account": "N00000002411"
}
}
],
"minimum_should_match": 1
}
}
}'
验证索引文档
curl --location --request GET 'http://172.21.0.31:9900/business/_validate/query?explain'
--header 'Content-Type: application/json'
--data-raw '{
"query": {
"bool": {
"should": [
{
"term": {
"def45310-019d-11ec-8372-1f0ef8ecd3d5": "王五"
}
}
],
"filter": [
{
"term": {
"account": "N00000002411"
}
}
],
"minimum_should_match": 1
}
}
}'
关闭索引
curl --location --request POST 'http://172.21.0.31:9900/business/_close'开启索引
curl --location --request POST 'http://172.21.0.31:9900/business/_open'索引迁移
curl --location --request POST 'http://172.21.0.31:9900/_reindex'
--header 'Content-Type: application/json'
--data-raw '{
"source": {
"index": "business"
},
"dest": {
"index": "business_bak"
}
}'
更新索引结构settings
只能对未设置过的字段进行更新,已存在的字段不能更新,只能重建索引
curl --location --request PUT 'http://172.21.0.31:9900/business/_settings'
--header 'Content-Type: application/json'
--data-raw '{
"analysis.analyzer.default.tokenizer": "1_25_tokenizer_grams",
"analysis.analyzer.default.filter": [
"unique",
"limit_filter"
],
"analysis.tokenizer.1_25_tokenizer_grams.type": "ngram",
"analysis.tokenizer.1_25_tokenizer_grams.min_gram": 1,
"analysis.tokenizer.1_25_tokenizer_grams.max_gram": 25,
"analysis.filter.limit_filter.type": "limit",
"analysis.filter.limit_filter.max_token_count": 500
}'
更新索引结构mappings
和更新索引结构settings用法相同
查看elasticsearch版本信息curl --location --request GET 'http://172.21.0.31:9900'查看elasticsearch所有数据量
curl --location --request GET 'http://172.21.0.31:9900/_count'查看elasticsearch某索引数据量
curl --location --request GET 'http://172.21.0.31:9900/business/_count'查看elasticsearch统计信息
curl --location --request GET 'http://172.21.0.31:9900/_cat/indices?v'异步索引迁移
curl --location --request POST 'http://172.21.0.31:9900/_reindex?wait_for_completion=false'
--header 'Content-Type: application/json'
--data-raw '{
"source": {
"index": "customer"
},
"dest": {
"index": "customer_bak"
}
}'
查看异步任务
curl --location --request GET 'http://172.21.0.31:9900/_tasks'取消异步任务
curl --location --request POST 'http://172.21.0.31:9900/_tasks/OfyS4qUGTW2OuA2BL5fYgQ:36133906/_cancel'查看指定索引的统计信息
curl --location --request GET 'http://172.21.0.31:9900/_cat/indices?v&index=customer_bak'



