Elasticsearch重建索引方法

本文介绍如何通过HTTP请求操作Elasticsearch中的索引,包括删除指定ID的数据、重建索引及其mapping配置的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. 删除 test_dev_log索引 (有就删除,没有就直接跳到第二点新建)

删除  id = 1 的数据,操作如下:

url:http://127.0.0.1:9200/index名称/type名称/1    HTTP方法采用DELETE的形式。

2. 重建索引 ,注意选择了  put, 创建索引和mapping都是put

http://192.168.8.183:9200/test_dev_log/

 

 

{
  "mappings": {
    "messages": {
      "_all": {
        "enabled": false
      },
      "_ttl": {
        "enabled": true,
        "default": 432000000
      },
      "dynamic_templates": [
        {
          "template_1": {
            "mapping": {
              "index": "not_analyzed",
              "type": "string"
            },
            "match": "*",
            "match_mapping_type": "string"
          }
        }
      ],
      "properties": {
        "11demo定时任务": {
          "type": "string",
          "index": "not_analyzed"
        },
        "[线程id": {
          "type": "string",
          "index": "not_analyzed"
        },
        "action": {
          "type": "string",
          "index": "not_analyzed"
        },
        "appName": {
          "type": "string",
          "index": "not_analyzed"
        },
        "application": {
          "type": "string",
          "index": "not_analyzed"
        },
        "bank": {
          "type": "string",
          "index": "not_analyzed"
        },
        "bankAccName": {
          "type": "string",
          "index": "not_analyzed"
        },
        "bankAccNo": {
          "type": "string",
          "index": "not_analyzed"
        },
        "bankId": {
          "type": "string",
          "index": "not_analyzed"
        },
        "bankName": {
          "type": "string",
          "index": "not_analyzed"
        },
        "body": {
          "type": "string",
          "index": "not_analyzed",
          "ignore_above": 256
        },
        "branch": {
          "type": "string",
          "index": "not_analyzed"
        },
        "class": {
          "type": "string",
          "index": "not_analyzed"
        },
        "companyId": {
          "type": "string",
          "index": "not_analyzed"
        },
        "cost": {
          "type": "string",
          "index": "not_analyzed"
        },
        "createTime": {
          "type": "string",
          "index": "not_analyzed"
        },
        "createTimeInLong": {
          "type": "string",
          "index": "not_analyzed"
        },
        "descrypedPwd": {
          "type": "string",
          "index": "not_analyzed"
        },
        "host": {
          "type": "string",
          "index": "not_analyzed"
        },
        "id": {
          "type": "string",
          "index": "not_analyzed"
        },
        "industryId": {
          "type": "string",
          "index": "not_analyzed"
        },
        "jm_timestamp": {
          "type": "date",
          "format": "strict_date_optional_time||epoch_millis"
        },
        "key": {
          "type": "string",
          "index": "not_analyzed"
        },
        "level": {
          "type": "string",
          "index": "not_analyzed"
        },
        "logType": {
          "type": "string",
          "index": "not_analyzed"
        },
        "logger": {
          "type": "string",
          "index": "not_analyzed"
        },
        "logisticsId": {
          "type": "string",
          "index": "not_analyzed"
        },
        "logisticsNo": {
          "type": "string",
          "index": "not_analyzed"
        },
        "menuPOList": {
          "type": "string",
          "index": "not_analyzed"
        },
        "method": {
          "type": "string",
          "index": "not_analyzed"
        },
        "mobile": {
          "type": "string",
          "index": "not_analyzed"
        },
        "mobileNo": {
          "type": "string",
          "index": "not_analyzed"
        },
        "msgId": {
          "type": "string",
          "index": "not_analyzed"
        },
        "myHeader": {
          "type": "string",
          "index": "not_analyzed"
        },
        "service": {
          "type": "string",
          "index": "not_analyzed"
        },
        "size": {
          "type": "string",
          "index": "not_analyzed"
        },
        "sql": {
          "type": "string",
          "index": "not_analyzed"
        },
        "statusCode": {
          "type": "string",
          "index": "not_analyzed"
        },
        "thread": {
          "type": "string",
          "index": "not_analyzed"
        },
        "timestamp": {
          "type": "string",
          "index": "not_analyzed"
        },
        "topic": {
          "type": "string",
          "index": "not_analyzed"
        },
        "type": {
          "type": "string",
          "index": "not_analyzed"
        },
        "ucenterMqTopic": {
          "type": "string",
          "index": "not_analyzed"
        },
        "userId": {
          "type": "string",
          "index": "not_analyzed"
        }
      }
    }
  }
}

 

Elasticsearch是一个强大的全文搜索引擎,用于实时数据分析和存储。如果你需要重建索引,通常是由于以下原因: **如何重建索引:** 1. **登录Elasticsearch集群:** 使用Kibana、Logstash或直接通过命令行工具(如curl)连接到你的Elasticsearch节点。 2. **确定要重建索引:** 在`/_cat/indices` API中查找你要重置或重建索引名称。 3. **暂停索引:** 在索引命名空间运行`PUT /your_index_name/_settings`并设置`index.blocks.write = true`,以防新数据写入影响重建过程。 4. **删除旧索引:** 使用`DELETE /your_index_name`删除现有的索引,但要注意这将丢失所有未备份的数据。 5. **创建新的索引:** 发起一个新的索引请求,例如`PUT /your_new_index_name`。你可以指定新索引的配置选项,比如分片数、副本数等。 6. **重新映射数据:** 如果需要,可以在新的索引上运行`POST /_reindex`操作,将老索引中的文档迁移到新索引。如果不需要迁移,可以跳过此步骤。 7. **恢复索引状态:** 当数据迁移完成后,取消对旧索引的封锁,即执行`PUT /your_index_name/_settings`并设置`index.blocks.write = false`。 8. **验证重建:** 最后,检查新索引的状态是否正常,可以通过`GET /_cat/health`查看集群健康状况。 **相关问题--:** 1. 如何防止数据丢失在重建过程中? 2. 是否可以直接在现有索引重建而无需先删除? 3. 新建索引时如何处理字段类型变化导致的问题?
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值