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"
        }
      }
    }
    }
  }
}
相关推荐
天硕国产存储技术站2 小时前
DualPLP 双重掉电保护赋能 天硕工业级SSD筑牢关键领域安全存储方案
大数据·人工智能·安全·固态硬盘
雷文成.思泉软件2 小时前
以ERP为核心、企微为门户,实现一体化集成
大数据·低代码·创业创新
东哥说-MES|从入门到精通3 小时前
数字化部分内容 | 十四五年规划和2035年远景目标纲要(新华社正式版)
大数据·人工智能·数字化转型·mes·数字化工厂·2035·十四五规划
南飞测绘视界4 小时前
上市公司绿色专利申请、授权数据(1999-2024年)
大数据·专利·上市公司
一个天蝎座 白勺 程序猿5 小时前
KingbaseES在政务领域的应用实践——武汉人社大数据平台“数字化服务新模式”
大数据·数据库·政务·kingbasees·金仓数据库
pale_moonlight5 小时前
十、 Scala 应用实践 (上)
大数据·开发语言·scala
Elasticsearch6 小时前
混合搜索无需头疼:使用 retrievers 简化混合搜索
elasticsearch
第二只羽毛6 小时前
遵守robots协议的友好爬虫
大数据·爬虫·python·算法·网络爬虫
Elastic 中国社区官方博客6 小时前
使用 A2A 协议和 MCP 在 Elasticsearch 中创建一个 LLM agent 新闻室:第二部分
大数据·数据库·人工智能·elasticsearch·搜索引擎·ai·全文检索
安达发公司7 小时前
安达发|告别手工排产!车间排产软件成为中央厨房的“最强大脑”
大数据·人工智能·aps高级排程·aps排程软件·安达发aps·车间排产软件