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

Apr 1, 2025

在WEB中子线程可以访问Request上下文

使用RequestContextHolder获取Request和Session对象 在JavaWeb中,可以通过RequestContextHolder类来获取当前线程的Request和Session对象。具体实现方式是先获取ServletRequestAttributes对象,再从中提取Reque

Dec 31, 2024

OpenSearch常用脚本

给数据添加属性 POST /your_index/_update_by_query { "script": { "source": "ctx._source.newField = 'new_value'", "lang": "painless" }, "query": {

Oct 27, 2024

HTML编译成应用程序

如果你想将 HTML 网页包装成 Windows 应用程序,可以使用 Electron。下面是详细步骤: 使用 Electron 创建 Windows 应用程序 1. 安装 Node.js 和 npm - 首先确保你安装了 Node.js 和 npm(Node.js 的包管理器)。你可以从 [Nod

OLDER

多线程的那些事

NEWER

Jvm参数

Recently Updated

  • Onlyoffice编译
  • K6+Playwright实现并发测试
  • 简单规则引擎
  • 在WEB中子线程可以访问Request上下文
  • onlyoffice配置

Trending Tags

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

Contents

©2025 十六小站. 陕ICP备2023009742号-2