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"
        }
      }
    }
    }
  }
}
相关推荐
冯RI375II694871 小时前
CPC认证的流程是怎样的呢
大数据
打码人的日常分享3 小时前
数据中心信息中心信息科管理制度
大数据·运维·网络·云计算·制造
AI周红伟4 小时前
周红伟:信创大模型企业级部署实操,Qwen3.5 昇腾企业级部署案例实操
大数据·人工智能·大模型·智能体
SickeyLee4 小时前
AI产品经理-大模型的智力之源与能力边界
大数据·人工智能
智海观潮5 小时前
Vanna-ai - 让自然语言对话SQL数据库成为可能,支持多种数据库,大模型和向量存储
大数据·nlp·aigc
阿甘编程点滴5 小时前
2026年适合企业产品介绍可商用的9款解说配音软件
大数据
AI周红伟7 小时前
周红伟:Qwen3.5-Plus - 企业级部署案例实操,Qwen3.5 LLM,包括 Qwen3.5-397B-A17B
大数据·人工智能·大模型·智能体
历程里程碑8 小时前
普通数组---合并区间
java·大数据·数据结构·算法·leetcode·elasticsearch·搜索引擎
T06205148 小时前
【面板数据】A股上市公司重污染行业分组数据集-含参考文献 (2000-2024年)
大数据
cm_chenmin8 小时前
Cursor最佳实践之三:MCP
大数据·elasticsearch·搜索引擎