avatar

十六小站

欢迎来到我的个人主页! 期待与您分享我的经验与故事,一起探索技术的无穷可能!

  • 首页
  • NAS专题
  • 关于
Home OpenSearch常用脚本
文章

OpenSearch常用脚本

Posted 2024-12-31 Updated 2025-01- 14
By 十六 已删除用户
5~7 min read

给数据添加属性

POST /your_index/_update_by_query
{
  "script": {
    "source": "ctx._source.newField = 'new_value'",
    "lang": "painless"
  },
  "query": {
    "match_all": {}
  }
}

查询所有的某个字段(如:tenantId)

POST /your_index/_search
{
  "size": 0, 
  "aggs": {
    "unique_tenant_ids": {
      "terms": {
        "field": "tenantId.keyword",
        "size": 10000 
      }
    }
  }
}

获取索引映射和设置

GET /old_index/_mappings

创建索引添加映射

PUT /new_index
{
  "settings": {
    // 旧索引的设置
  },
  "mappings": {
    // 旧索引的映射
  }
}

索引数据迁移

POST /_reindex
{
  "source": {
    "index": "old_index"
  },
  "dest": {
    "index": "new_index"
  }
}

索引添加别名

POST /_aliases
{
  "actions": [
    { "add": { "index": "new_index", "alias": "old_index" } }
  ]
}

移除别名

POST /_aliases
{
  "actions": [
    { "remove": { "index": "new_index", "alias": "new_index" } }
  ]
}

搜索迁移任务

GET /_tasks?actions=*reindex&detailed=true

停止指定任务

POST /_tasks/task_id_1/_cancel

//删除所有reindex任务
POST /_tasks/_cancel?actions=*reindex

批量操作

delete语句只需一行,其他需要两行,必须是两行。

POST /_bulk
{"create": {"_index": "test_index", "_id": 11}}
{"test_field": "test_bulk", "counter":"100"}
{"update": {"_index": "test_index", "_id": 3}}
{"doc": {"test_field": "bulk test"}}
{"delete": {"_index": "test_index", "_id": 5}}

后端, 菜鸟入坑
中间件
License:  CC BY 4.0
Share

Further Reading

Sep 30, 2025

微服务之Auth篇

auth服务重要是认证授权,签发jwt token使用。 生成密钥对 # 在项目 src/main/resources 下生成 jwt.jks(演示用,生产用更严格的密码/keystore) keytool -genkeypair \ -alias jwt \ -keyalg RSA \

Sep 6, 2025

SpringBoot3.X-2(缓存Redis/memory)

本文主要是实现缓存的集成,由于是单体项目 ,目前整合了内存缓存和Redis缓存两种,可以通过配置来切换。 引入依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-sta

Sep 5, 2025

SpringBoot3.X-1(MP+Druid)

本次基于springboot-3.5.5,先附上文档地址:https://docs.spring.io/spring-boot/reference/data/sql.html 初始化springboot项目 项目创建步骤不做记录 集成mybaits-plus</

OLDER

多线程的那些事

NEWER

Jvm参数

Recently Updated

  • KubeShpere部署(4.1.2)
  • 微服务之Auth篇
  • 记一次前端优化(vue2)
  • SpringBoot3.X-2(缓存Redis/memory)
  • SpringBoot3.X-1(MP+Druid)

Trending Tags

Java Docker 前端 中间件 数据库 群晖 unraid

Contents

©2025 十六小站. Some rights reserved.

Using the Halo theme Chirpy