Elasticsearch 认证模拟题 - 5

一、题目

.在集群上有一个索引 food_ingredient,搜索需要满足以下要求:

  1. 三个字段 manufacturernamebrand 都能匹配到文本 cake mix
  2. 高亮 字段 name,并加标签
  3. 排序,对字段 brand 正序,_score 降序,返回 20 个文档
rust 复制代码
# 创建符合条件的 task 索引,设置 field 字段,并写入数据
PUT food_ingredient
{
  "mappings": {
    "properties": {
      "manufacturer":{
        "type": "text"
      },
      "name":{
        "type": "text"
      },
      "brand":{
        "type": "text"
      }
    }
  }
}

# 写入数据
POST food_ingredient/_bulk
{"index":{}}
{"manufacturer": "cake mix", "name": "cake mix", "brand": "cake mix"}
1.1 考点
  1. must 查询
  2. 高亮
  3. 排序
1.2 答案
rust 复制代码
GET food_ingredient/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "manufacturer": "cake mix"
          }
        },
        {
          "match": {
            "name": "cake mix"
          }
        },
        {
          "match": {
            "brand": "cake mix"
          }
        }
      ]
    }
  },
  "highlight": {
    "fields" : {
      "name" : { "pre_tags" : ["<em>"], "post_tags" : ["</em>"] }
    }
  }, 
  "sort": [
    {
      "brand.keyword": {
        "order": "asc"
      }
    },
    {
      "_score": {
        "order": "desc"
      }
    }
  ]
}

二、题目

集群中有 earthquakes 索引,timestamp 字段的格式为 yyyy-MM-dd HH:mm:ss。对 earthquakes 索引按月分桶,并且对 magnitudedepth 进行最大值聚合。

rust 复制代码
# 创建索引
PUT earthquakes
{
  "settings": {
    "number_of_replicas": 0
  },
  "mappings": {
    "properties": {
      "timestamp":{
        "type": "date",
        "format": "yyyy-MM-dd HH:mm:ss"
      },
      "magnitude":{
        "type": "float"
      },
	  "type":{
	    "type":"integer"
	  },
	  "depth":{
	    "type":"float"
	  }
    }
  }
}

# 导入数据
POST earthquakes/_bulk
{"index":{}}
{"timestamp":"2012-01-01 12:12:12", "magnitude":4.56, "type":1, "depth":10}
{"index":{}}
{"timestamp":"2012-01-01 15:12:12", "magnitude":6.46, "type":2, "depth":11}
{"index":{}}
{"timestamp":"2012-02-02 13:12:12", "magnitude":4, "type":2, "depth":5}
{"index":{}}
{"timestamp":"2012-03-02 13:12:12", "magnitude":6, "type":3, "depth":8}
{"index":{}}
{"timestamp":"1967-03-02 13:12:12", "magnitude":6, "type":2, "depth":6}
2.1 考点
  1. 分桶聚合
  2. 指标聚合
2.2 答案
rust 复制代码
GET earthquakes/_search
{
  "size": 0,
  "aggs": {
    "sales_over_time": {
      "date_histogram": {
        "field": "timestamp",
        "calendar_interval": "month"
      },
    "aggs": {
      "max_magnitude": {
        "max": {
          "field": "magnitude"
        }
      },
      "max_depth": {
        "max": {
          "field": "depth"
        }
      }
    }
    }
  }
}
相关推荐
重生的黑客12 分钟前
Git 本地版本管理与分支管理:从零理解工作区、回退、冲突与开发流程
数据库·git·elasticsearch
大模型探索者7 小时前
2026 企业智能体平台选型指南:从通用到行业深耕,怎么选?
大数据·人工智能
阿三081212 小时前
跨境电商售后自动化分级标准:哪些能全自动、哪些半自动、哪些禁止自动化
大数据·人工智能·自动化
游戏新手村14 小时前
蝴蝶图在餐饮门店数据可视化中的应用
大数据·信息可视化·产品经理·数据可视化
GlobalHRTalk15 小时前
埃及名义雇主EOR业务概述与市场发展优势分析
大数据·运维·人工智能
ji_shuke15 小时前
从零深入:基于 Playwright + Pytest + Allure 的企业级 Web 端到端自动化测试框架实战
前端·自动化测试·docker·jenkins·pytest·allure·playwright
码云数智-园园16 小时前
Hyperf 协程 PHP 实战:传统 PHP 如何实现高并发服务
大数据
找方案16 小时前
北京砸1亿支持智能体:Agent创业迎来黄金窗口期
大数据·人工智能·microsoft
Elasticsearch16 小时前
你的 SLO 已经告急;下面介绍如何在 Elastic Observability 中找出罪魁祸首
elasticsearch
Black蜡笔小新16 小时前
EasyAIS+国标GB28181视频监控平台EasyCVR强强联动,全域视频AI识别能力落地!
大数据·人工智能·音视频