Elasticsearch 认证模拟题 -2

一、题目

有一个索引 task3,其中有 fieldafieldbfieldcfielde 现要求对 task3 重建索引,重建后的索引新增一个字段 fieldg 其值是fieldafieldbfieldcfielde 的值拼接而成。

rust 复制代码
# 创建符合条件的 task3 索引,设置 field字段,并写入数据
PUT task3
{
  "mappings": {
    "properties": {
      "fielda":{
        "type": "keyword"
      },
      "fieldb":{
        "type": "keyword"
      },
      "fieldc":{
        "type": "keyword"
      },
      "fielde":{
        "type": "keyword"
      }
    }
  }
}

POST task3/_bulk
{"index":{}}
{"fielda":"aa","fieldb":"bb","fieldc":"cc","fielde":"dd"}
{"index":{}}
{"fielda":"中华","fieldb":"人民","fieldc":"共和国","fielde":"万岁"}
1.1 考点
  1. 重建索引
  2. 脚本
  3. 或可以通过 管道 来解
1.2 答案
rust 复制代码
# 定义新的索引
PUT task4
{
  "mappings": {
    "properties": {
      "fielda":{
        "type": "keyword"
      },
      "fieldb":{
        "type": "keyword"
      },
      "fieldc":{
        "type": "keyword"
      },
      "fielde":{
        "type": "keyword"
      },
      "fieldg":{
        "type": "keyword"
      }
    }
  }
}

#  重建索引
POST _reindex
{
  "source": {
    "index": "task3"
  },
  "dest": {
    "index": "task4"
  },
  "script": {
    "source": """
    ctx._source.fieldg = "";
    ctx._source.fieldg = ctx._source.fieldg + ctx._source.fielda + "-";
    ctx._source.fieldg = ctx._source.fieldg + ctx._source.fieldb + "-";
    ctx._source.fieldg = ctx._source.fieldg + ctx._source.fieldc + "-";
    ctx._source.fieldg = ctx._source.fieldg + ctx._source.fielde;
    """
  }
}

二、题目

在集群上有一个索引 task1,编写一个查询并满足以下要求:

  1. 定义一个名为 a 的运行时字段,通过 a 字段实现以下聚合(a 字段的值等于 b 字段减去 c 字段)

  2. 聚合a值小于-2的文档

  3. 聚合-5到5之间的文档

  4. 聚合大于5的文档

  5. 建立测试索引

rust 复制代码
# 创建索引
PUT task1
{
  "mappings": {
    "properties": {
      "b":{
        "type": "double"
      },
      "c":{
        "type": "double"
      }
    }
  }
}

# 写入数据
POST task1/_bulk
{"index":{}}
{"b":2,"c":3}
{"index":{}}
{"b":5,"c":1}
{"index":{}}
{"b":6,"c":1}
{"index":{}}
{"b":1,"c":7}
2.1 考点
  1. 聚合这里用到的范围聚合
  2. 运行时字段
2.2 答案
rust 复制代码
# 使用 runtime_mappings 进行聚类
GET task1/_search
{
  "runtime_mappings": {
    "a": {
      "type": "double",
      "script": {
        "source": """
          emit(doc['b'].value - doc['c'].value)
        """
      }
    }
  },
  "aggs": {
    "bucket_ranges": {
      "range": {
        "field": "a",
        "ranges": [
          { "to": -2 },
          { "from": -5, "to": 5 },
          { "from": 5 }
        ]
      }
    }
  }
}
相关推荐
鸿乃江边鸟6 分钟前
从 SortExec 的排序来谈 Spark Tungsten 计划中的缓存友好特性
大数据·spark
朗心心理11 小时前
朗心科技:以数智化引领心理健康服务新标杆
大数据·人工智能·科技·心理健康·朗心科技·数智化心理育人·一站式心理中心建设
无忧智库11 小时前
破局与重构:大型集团化协同管理平台的全景式深度解构(PPT)
大数据
码云数智-大飞13 小时前
进程、线程与协程:并发模型的演进与 Go 语言的 GMP 革命
大数据
XiaoMu_00114 小时前
基于大数据的糖尿病数据分析可视化
大数据·数据挖掘·数据分析
阿里云大数据AI技术14 小时前
Celeborn 如何让 EMR Serverless Spark 的 Shuffle 舒心、放心、安心
大数据·spark
AI营销快线14 小时前
AI营销获客难?原圈科技深度解析SaaS系统增长之道
大数据·人工智能
星幻元宇VR15 小时前
VR环保学习机|科技助力绿色教育新模式
大数据·科技·学习·安全·vr·虚拟现实
CryptoPP16 小时前
开发者指南:构建实时期货黄金数据监控系统
大数据·数据结构·笔记·金融·区块链
ZGi.ai17 小时前
生产级 Agent 编排 从单一 LLM 调用到多智能体工作流的工程设计
大数据·数据库·人工智能