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 }
        ]
      }
    }
  }
}
相关推荐
嘉讯科技HIS系统1 小时前
嘉讯科技:医疗信息化、数字化、智能化三者之间的关系和区别
大数据·数据库·人工智能·科技·智慧医疗
大只鹅2 小时前
Springboot3.3.4使用spring-data-elasticsearch整合Elasticsearch7.12.1
spring boot·elasticsearch
lifallen2 小时前
Paimon vs. HBase:全链路开销对比
java·大数据·数据结构·数据库·算法·flink·hbase
爱吃面的猫2 小时前
大数据Hadoop之——Hbase下载安装部署
大数据·hadoop·hbase
viperrrrrrrrrr72 小时前
大数据(1)-hdfs&hbase
大数据·hdfs·hbase
拓端研究室4 小时前
专题:2025即时零售与各类人群消费行为洞察报告|附400+份报告PDF、原数据表汇总下载
大数据·人工智能
武子康4 小时前
大数据-30 ZooKeeper Java-API 监听节点 创建、删除节点
大数据·后端·zookeeper
小手WA凉4 小时前
Hadoop之MapReduce
大数据·mapreduce
二闹5 小时前
SLF4J/Logback 配置与 ELK 集成实战指南
后端·elasticsearch·logstash
AgeClub5 小时前
服务600+养老社区,Rendever如何通过“VR+养老”缓解老年孤独?
大数据·人工智能