ElasticSearch 常用api

ㅤㅤㅤ
ㅤㅤㅤ
ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ(活得快乐的最重要因素是人生有事干、有人可去爱,以及生命中有所冀望。——约瑟夫·艾迪生)
ㅤㅤㅤ
ㅤㅤㅤ
ㅤㅤㅤㅤㅤㅤㅤㅤㅤ在这里插入图片描述
ElasticSearch 数据迁移方案

ElasticSearch版本说明

{
“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”
}

ElasticSearch 常用api

创建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'
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值