Elasticsearch 认证模拟题 - 6

一、题目

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

  1. 集群的 brand 字段包含关键字 Yoo-HooYooHoo ,不管搜索 Yoo-Hoo 还是 YooHoo,它的结果应该一样,都是3个。
  2. task2_newtask2docmapping 一样,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_dateend_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"
  }
}
相关推荐
电商API_1800790524711 分钟前
批量获取电商商品数据的主流技术方法全解析
大数据·数据库·人工智能·数据分析·网络爬虫
Zoey的笔记本1 小时前
敏捷与稳定并行:Scrum看板+BPM工具选型指南
大数据·前端·数据库·python·低代码
俊哥大数据1 小时前
【项目7】 基于Flink新闻资讯大数据推荐系统
大数据·flink
Coder_Boy_2 小时前
基于SpringAI的在线考试系统-企业级软件研发工程应用规范实现细节
大数据·开发语言·人工智能·spring boot
AIGCExplore2 小时前
Jenkins 全局配置及工具验证教程
java·servlet·jenkins
Hello.Reader2 小时前
Flink State Processor API 读写/修复 Savepoint,把“状态”当成可查询的数据
大数据·flink
木风小助理2 小时前
Elasticsearch生产环境最佳实践指南
大数据·elasticsearch·搜索引擎
hg01183 小时前
筑梦非洲:中国电建以实干绘就中非合作新图景
大数据
WZGL12303 小时前
智慧养老方兴未艾,“AI+养老”让银龄老人晚年更美好
大数据·人工智能·物联网·生活·智能家居
檐下翻书1733 小时前
PC端免费跨职能流程图模板大全 中文
大数据·人工智能·架构·流程图·论文笔记