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"
        }
      }
    }
    }
  }
}

相关推荐

  1. Elasticsearch 认证模拟 - 6

    2024-06-07 20:14:04       27 阅读
  2. Elasticsearch 认证模拟 - 10

    2024-06-07 20:14:04       31 阅读
  3. Elasticsearch 认证模拟 - 12

    2024-06-07 20:14:04       35 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-06-07 20:14:04       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-06-07 20:14:04       106 阅读
  3. 在Django里面运行非项目文件

    2024-06-07 20:14:04       87 阅读
  4. Python语言-面向对象

    2024-06-07 20:14:04       96 阅读

热门阅读

  1. EmotionPrompt 论文精读

    2024-06-07 20:14:04       28 阅读
  2. 【设计模式】策略模式(行为型)⭐⭐

    2024-06-07 20:14:04       29 阅读
  3. Secure Boot原理和高通芯片Secure Boot原理

    2024-06-07 20:14:04       29 阅读
  4. 如何评价GPT-4o?

    2024-06-07 20:14:04       24 阅读
  5. 数学部分学习

    2024-06-07 20:14:04       25 阅读
  6. 书籍数字字符串转换为字母组合的种数(4)0607

    2024-06-07 20:14:04       32 阅读
  7. Qt程序打包

    2024-06-07 20:14:04       31 阅读