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"
        }
      }
    }
    }
  }
}
相关推荐
源码宝15 分钟前
新一代医院信息系统云HIS,多租户共享,java版HIS+EMR+LIS全套源码
java·大数据·源码·云his·his系统·源代码·医院信息系统
跨境卫士-小汪43 分钟前
多渠道获客复杂化跨境卖家如何优化整体结构
大数据·人工智能·产品运营·跨境电商·跨境
研究点啥好呢1 小时前
Github热门项目推荐 | 开放数据的新时代
大数据·人工智能·机器学习·github·数据
清 晨2 小时前
社媒引流不稳定跨境卖家如何建立长期流量池
大数据·人工智能·新媒体运营·跨境·营销策略
历程里程碑2 小时前
二叉树---二叉树的最大深度
大数据·数据结构·算法·elasticsearch·搜索引擎·全文检索·深度优先
七夜zippoe2 小时前
OpenClaw 飞书深度集成:知识库管理
大数据·人工智能·飞书·集成·openclaw
黄焖鸡能干四碗3 小时前
网络安全风险评估报告(WORD版本)
大数据·运维·网络·人工智能·制造
ZStack开发者社区3 小时前
金融云新范式:ZStack如何用“一套架构“打通全域全场景
大数据·人工智能
毅炼3 小时前
MySQL 常见问题总结(1)
java·大数据·数据库
GEO索引未来3 小时前
为什么做GEO需要一套好的数据系统?
大数据·人工智能·ai·chatgpt·googlecloud