Elasticsearch 认证模拟题 - 12

一、题目

在集群上有 task2 索引,请重建它到 task2_new 索引上,并满足以下要求:

  1. task2 索引的 a 字段包含有关键字 Yoo-HooYooHoo ,不管搜索 Yoo-Hoo 还是YooHoo 它们的结果应该一样
  2. task2_newtask2mapping 应该一样
rust 复制代码
POST task2/_bulk
{"index":{}}
{"a":"Yoo-Hoo"}
{"index":{}}
{"a":"YooHoo"}
1.1 考点
  1. 分词器
1.2 答案
rust 复制代码
# 创建索引结构,自定义分词器
PUT task2_new
{
  "settings": {
    "analysis": {
      "analyzer": {
        "my_custom_analyzer": {
          "type": "custom",
          "tokenizer": "standard",
          "char_filter": ["remove-"],
          "filter": []
        }
      },
      "char_filter": {
          "remove-": {
            "type": "mapping",
            "mappings": [
              "- => "
            ]
          }
        }
    }
  },
  "mappings": {
    "properties": {
      "a":{
        "type": "text",
        "analyzer": "my_custom_analyzer"
      }
    }
  }
}

# 写入数据
POST task2_new/_bulk
{"index":{}}
{"a":"Yoo-Hoo"}
{"index":{}}
{"a":"YooHoo"}

# 验证结果
GET task2_new/_search
{
  "query": {
    "match": {
      "a": "YooHoo"
    }
  }
}
GET task2_new/_search
{
  "query": {
    "match": {
      "a": "Yoo-Hoo"
    }
  }
}

二、题目

earthquakes 索引中包含了过去11个月的地震信息,请通过一句查询,获取以下信息

  1. 过去11个月,每个月的平均地震等级(magnitude)
  2. 过去11个月里,平均地震等级最高的一个月及其平均地震等级
  3. 搜索不能返回任何文档
rust 复制代码
# 创建索引
PUT earthquakes
{
  "settings": {
    "number_of_replicas": 0
  },
  "mappings": {
    "properties": {
      "timestamp": {
        "type": "date",
        "format": "yyyy-MM-dd HH:mm:ss"
      },
      "magnitude": {
        "type": "float"
      }
    }
  }
}

# 导入数据
POST earthquakes/_bulk
{"index":{}}
{"timestamp":"2012-01-01 12:12:12", "magnitude":4.56}
{"index":{}}
{"timestamp":"2012-01-01 15:12:12", "magnitude":6.46}
{"index":{}}
{"timestamp":"2012-02-02 13:12:12", "magnitude":4}
{"index":{}}
{"timestamp":"2012-03-02 13:12:12", "magnitude":6}
{"index":{}}
{"timestamp":"1967-03-02 13:12:12", "magnitude":6}
2.1 考点
  1. 分桶聚类
  2. 指标聚类
  3. 管道聚类
2.2 答案
rust 复制代码
POST earthquakes/_search
{
  "size": 0,
  "aggs": {
    "every_month": {
      "date_histogram": {
        "field": "timestamp",
        "calendar_interval": "month",
        "format": "yyyy-MM-dd"
      },
      "aggs": {
        "avg_magnitude": {
          "avg": {
            "field": "magnitude"
          }
        }
      }
    },
    "max_magnitude": {
      "max_bucket": {
        "buckets_path": "every_month>avg_magnitude" 
      }
    }
  }
}
相关推荐
Tianyanxiao34 分钟前
华为×小鹏战略合作:破局智能驾驶深水区的商业逻辑深度解析
大数据·人工智能·经验分享·华为·金融·数据分析
线条13 小时前
大数据 ETL 工具 Sqoop 深度解析与实战指南
大数据·sqoop·etl
mazhafener12310 小时前
智慧照明:集中控制器、单双灯控制器与智慧灯杆网关的高效协同
大数据
打码人的日常分享10 小时前
物联网智慧医院建设方案(PPT)
大数据·物联网·架构·流程图·智慧城市·制造
Lansonli11 小时前
大数据Spark(六十一):Spark基于Standalone提交任务流程
大数据·分布式·spark
Rverdoser13 小时前
电脑硬盘分几个区好
大数据
傻啦嘿哟13 小时前
Python 数据分析与可视化实战:从数据清洗到图表呈现
大数据·数据库·人工智能
Theodore_102213 小时前
大数据(2) 大数据处理架构Hadoop
大数据·服务器·hadoop·分布式·ubuntu·架构
簌簌曌14 小时前
CentOS7 + JDK8 虚拟机安装与 Hadoop + Spark 集群搭建实践
大数据·hadoop·spark
Theodore_102216 小时前
大数据(1) 大数据概述
大数据·hadoop·数据分析·spark·hbase