当前位置: 首页 > news >正文

Elasticsearch 认证模拟题 - 5

一、题目

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

  1. 三个字段 manufacturernamebrand 都能匹配到文本 cake mix
  2. 高亮 字段 name,并加标签
  3. 排序,对字段 brand 正序,_score 降序,返回 20 个文档
# 创建符合条件的 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 答案
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 进行最大值聚合。

# 创建索引
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 答案
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"
        }
      }
    }
    }
  }
}

相关文章:

  • 结构体相关习题的补充
  • 从0开始学统计-什么是回归?
  • Nuxt.js静态生成与动态路由策略
  • 【论文解读】Performance of AV1 Real-Time Mode
  • 基于java的CRM客户关系管理系统(一)
  • Tomcat
  • 21.Redis之分布式锁
  • mongodb数据库查询调优之explain方法详解
  • 数据结构的希尔排序(c语言版)
  • 【iOS】didReceiveMemoryWarning实例方法
  • 计算机网络基础知识(持续更新中)
  • 【计算机网络】——物理层(图文并茂)
  • 数据结构的快速排序(c语言版)
  • 智能网联汽车翻译
  • 12 FreeRTOS 调试与优化
  • 【Linux网络】端口及UDP协议
  • vscode编辑器创建分支注意事项?!
  • 4月啤酒品类线上销售数据分析
  • Java项目对接redis,客户端是选Redisson、Lettuce还是Jedis?
  • K8S认证|CKA题库+答案| 14. 排查故障节点
  • 耿军强任陕西延安市领导,此前任陕西省公安厅机场公安局局长
  • 新华时评:中国维护国际经贸秩序的立场坚定不移
  • 印度最新发声:对所有敌对行动均予以反击和回应,不会升级冲突
  • 领证不用户口本,还需哪些材料?补领证件如何操作?七问七答
  • 拿出压箱底作品,北京交响乐团让上海观众享受音乐盛宴
  • 上报集团社长李芸:发挥媒体优势,让中非民心在数字时代更深层互联互通