Elasticsearch 认证模拟题 - 6

一、题目

在集上有一个索引 task2,brand 字段 match 搜索 Yoo-Hoo 有 3 个文档返回,match 搜索 YooHoo 有 10 个文档返回,请重建 索引 task2 到 task2_new 索引上,并满足以下要求:

  1. 集群的 brand 字段包含关键字 Yoo-Hoo 和 YooHoo ,不管搜索 Yoo-Hoo 还是 YooHoo,它的结果应该一样,都是3个。
  2. task2_new 和 task2 的 doc 和 mapping 一样,mapping 要拷贝,不能直接 reindex
1.1 考点
  1. 分词器
  2. Character filters
  3. 重建索引
1.2 答案
rust 复制代码
# 新建索引,自定义分词器
PUT task2_new
{
  "settings": {
    "analysis": {
      "analyzer": {
        "custom_analyzer": { 
          "char_filter": [
            "map"
          ],
          "tokenizer": "standard",
          "filter": []
        }
      },
      "char_filter": {
        "map": { 
          "type": "mapping",
          "mappings": [
            "- => "
          ]
        }
      }
    }
  }, 
  "mappings": {
    "properties": {
      "brand":{
        "type": "text",
        "analyzer": "custom_analyzer"
      }
    }
  }
}

# 将 task2 的数据写入到 task2_new
POST _reindex
{
  "source": {
    "index": "task2"
  },
  "dest": {
    "index": "task2_new"
  }
}

# 查询验证
GET task2_new/_search
{
  "query": {
    "match": {
      "brand": "Yoo-Hoo"
    }
  }
}

二、题目

对索引 task9 编写一个查询模板,并满足以下要求:

  1. 使用 a_01 参数查询 a 字段
  2. 使用 start_date 和 end_date 参数范围查询 timestamp 字段
  3. 如果没有提供 end_date 参数,那么结束时间默认是现在
  4. 查询结果中 b 字段必须是 active,

利用查询模板,编写查询语句,查询 2018年6月1日 到 现在 的数据,a 字段包含关键字 aaa。

rust 复制代码
# 创建索引
PUT task9
{
  "mappings": {
    "properties": {
      "a":{
        "type": "text"
      },
      "b":{
        "type": "keyword"
      },
      "timestamp":{
        "type": "date"
      }
    }
  }
}

# 写入数据
POST /task9/_bulk
{"index": {}}
{"a":"aaa AAA", "b":"active", "timestamp":"2021-11-11T11:21:21.000Z"}
{"index": {}}
{"a":"aaa AAA", "b":"active", "timestamp":"2022-11-11T11:21:21.000Z"}
{"index": {}}
{"a":"AAA", "b":"b", "timestamp":"2023-11-11T11:21:21.000Z"}
2.1 考点
  1. 查询模板
  2. 查询模板的默认值
2.2 答案
rust 复制代码
# 创建模板
PUT _scripts/search-template
{
  "script": {
    "lang": "mustache",
    "source": {
      "query": {
        "bool": {
          "must": [
            {
              "range": {
                "timestamp": {
                  "gte": "{{start_date}}",
                  "lte": "{{end_date}}{{^end_date}}now{{/end_date}}"
                }
              }
            },
            {
              "match": {
                "a": "{{a_01}}"
              }
            },
            {
              "term": {
                "b": {
                  "value": "active"
                }
              }
            }
          ]
        }
      }
    },
    "params": {
      "end_date": "now"
    }
  }
}

# 预览模板
POST _render/template
{
  "id": "search-template",
  "params": {
    "a_01": "hello world",
    "start_date": "2022-11-11T11:21:21.000Z"
  }
}

# 使用模板搜索
GET task9/_search/template
{
  "id": "search-template",
  "params": {
    "a_01": "aaa",
    "start_date": "2022-11-11T11:21:21.000Z"
  }
}
相关推荐
微三云马玮均—GEO源码系统 私有化部署4 小时前
消费返物业费:消费+服务趋势的必然产物!
大数据·人工智能·物联网·区块链·生活
workflower6 小时前
AI system product quality model
大数据·人工智能·机器学习·云计算·无人机
yl45306 小时前
硫酸泄露处理生产商怎么选才够专业
大数据·人工智能·python
xianghongtao01166 小时前
麦肯锡2026技术趋势02_智能体AI_研究解读
大数据·人工智能
数字化顾问7 小时前
(138页PPT)四大咨询矿业集团流程梳理与优化报告(附下载方式)
大数据·人工智能
yukai080088 小时前
【203篇系列】056 我的Agent系统
大数据·elasticsearch·搜索引擎
IT大白鼠8 小时前
搜索系列 · 第 08 篇——面试收官:高频题与全景总结
elasticsearch·面试·nosql
yuanxi20010 小时前
青海共和百万千瓦光伏光热项目并网发电:大客户销售如何用价值力抓住能源大单
大数据·职场和发展·能源·创业创新·学习方法
W***259212 小时前
2026深度解读:Work Agent长程任务的执行机制与落地能力
大数据·人工智能
卷毛迷你猪13 小时前
快速实验篇(B07 )Session 会话化与序列
大数据·hive·hadoop