OpenSearch常用脚本
给数据添加属性
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