elasticSearch常用命令

参考地址 https://www.yiibai.com/elasticsearch/elasticsearch-getting-start.html

集群

   1. 查看集群状态

   GET http://localhost:9200/_cluster/health?pretty

   2. 查看指定索引库的健康状态

   GET http://localhost:9200/_cluster/health/index_name?pretty

   GET http://localhost:9200/_cluster/health/index_name,index_name2?pretty

   3. 查看es集群节点

   GET http://localhost:9200/_cat/nodes?v

查看所有索引及其状态

   GET http://localhost:9200/_cat/indices?v&pretty

索引操作

   1. 创建索引

   PUT http://127.0.0.1:9200/<index>

   通过如下参数来指定分片数、副本数量

   {

    "settings": {

    "number_of_shards": 3,

    "number_of_replicas": 2

    }

    }

    2. 查看索引及结构

    GET http://127.0.0.1:9200/<index>/_mapping?pretty

    

    2. 修改索引 只能别名实现

    

    3. 删除索引

    DELETE http://127.0.0.1:9200/<index>

    

    4. 查看索引别名

    GET http://127.0.0.1:9200/_cat/aliases?v&pretty

    

    创建索引别名

    POST http://127.0.0.1:9200/_aliases

    {

      "actions" : [{"add" : {"index" : "xxx" , "alias" : "ss"}}]

    }

    5. 删除某一索引下全部数据

    POST http://127.0.0.1:9200/<index>/_delete_by_query

    {

      "query": {

        "match_all": {}

      }

    }

    6. 查看索引数据

    GET http://127.0.0.1:9200/<index>/_search

文档操作

    GET http://192.168.43.45:9200/index/type/_search

    

    ignore_unavailable = true

    如果URL中存在的一个或多个索引不存在,则不会发生错误或操作不会停止

    

    GET http://localhost:9200/<index>/<type>/<id>

添加mapping

    1.使用put方法加字段

    my_index/_mapping/_doc    _doc 任意 type名称

    

    {

      "properties": {

        "字段":{

            "type": "类型"

        }

      }

    }

    

    2.设置默认值 使用post

    

    my_index/my_type/_update_by_query?refresh&conflicts=proceed

    

    {

      "script": {

        "lang": "painless",

        "inline": "if (ctx._source.字段== null) {ctx._source.字段= 0}"

      }

    }

    

    curl -i -X POST \

   -H "Content-Type:application/json" \

   -d \

'{

  "script": {

    "lang": "painless",

    "inline": "if (ctx._source.DoctorType== null) {ctx._source.DoctorType= 0}"

  }

}' \

-u elastic:medlinker123456 'http://127.0.0.1:9200/prescription_search_v1/_update_by_query?refresh&conflicts=proceed'

_update_by_query 指导

https://blog.csdn.net/gui66497/article/details/81389037

字段类查询查询 match,term

字段类查询语法

1. match query

{

     "query": {

          "match": {

               "ID": 9498961

          }

     }

}

elasticdump操作

    curl基础鉴权

    curl -u elastic:Medlinker@elastic http://es-cn-oew1t3ioh000k4i6t.public.elasticsearch.aliyuncs.com:9200

    

    elasticdump命令使用

    直接迁移会导致迁移后分片数量为主1,副1。

    

    推荐在迁移前,在新集群中建立索引分片,然后进行数据迁移。

    

    参数介绍:

    

    --input   数据源地址,地址后加入索引名

    

    --output   目标地址,地址后加入原有索引名或新索引名

    

    --type   data为数据拷贝

    

                mapping拷贝映射(意思是把原始索引的mapping结构迁移给目标索引)

    

                analyzer拷贝analyzer分词

    

    --limit   限制每次移动多少个文件(默认是100)

    

    2.1 备份

    

    ./elasticdump --input=http://118.31.236.23:9200/develop_prescription_search_v1 --output=./develop_prescription_search_v1.json

    2.2 还原

    

    ./elasticdump --input=/opt/esdump/test.json --output=http:/192.168.1.3:9200/test --type=data

    2.3 数据迁移

    

    ./elasticdump --input=http:/192.168.1.2:9200/test --output=http:/192.168.1.3:9200/test --type=data

     2.4 备份并压缩

    

    ./elasticdump --input=http://118.31.236.23:9200/develop_prescription_search_v1 --output=$ | gzip > ./prescription_search_v1.gz

    

    

    

    

    

    elasticdump \

  --input=http://192.168.5.101:9200/my_index --httpAuthFile=./auth.ini\

  --output=http://192.168.5.202:9200/my_index --httpAuthFile=./auth.ini\

  --type=analyzer

elasticdump \

  --input=http://192.168.5.101:9200/my_index \

  --output=http://192.168.5.202:9200/my_index \

  --type=mapping

elasticdump \

  --input=http://192.168.5.101:9200/my_index \

  --output=http://192.168.5.202:9200/my_index \

  --type=data

  

  统计数量:

  POST /qa_prescription_search/prescription_type/_count

  {

    "query": {

        "bool": {

            "must": [

                {

                    "match": {

                        "PrTagType": {

                            "operator": "AND",

                            "query": 5

                        }

                    }

                }

            ]

        }

    }

}

POST /index/type/_update_by_query?refresh&conflicts=proceed

{

    "query": {

        "match": {

            "DoctorId": 100

        }

    },

    "script": {

        "lang": "painless",

        "inline": "ctx._source['City']='chengdu';ctx._source['HospitalName']='第二人民医院';ctx._source['Province']='四川省'"

    }

}

post index/type/_delete_by_query  删除某字段不为空的数据

{

  "query": {

    "bool": {

      "must": {

        "exists": {

          "field": "字段名"

        }

      }

    }

  }

}

分词测试

GET /_analyze

{

"text": "蓝瘦香菇",

"analyzer": "ik_pinyin_analyzer"   //ik_smart ik_max_word

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值