Elasticsearch 认证模拟题 - 22

一、题目

索引 task 索引中文档的 fielda 字段内容包括了 hello & world ,索引后,要求使用 match_phrase query 查询 hello & world 或者 hello and world 都能匹配该文档

1.1 考点
  1. 分词器
1.2 答案
rust 复制代码
# 创建符合条件的 task 索引,设置 field 字段,并写入数据
PUT task
{
"settings": {
    "analysis": {
      "analyzer": {
        "my_analyzer": {
          "tokenizer": "standard",
          "char_filter": [
            "my_mappings_char_filter"
          ]
        }
      },
      "char_filter": {
        "my_mappings_char_filter": {
          "type": "mapping",
          "mappings": [
            "& => and"
          ]
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "fielda":{
        "type": "text",
        "analyzer": "my_analyzer"
      }
    }
  }
}

# 写入数据
POST task/_bulk
{"index":{}}
{"fielda":"hello & world"}
{"index":{}}
{"fielda":"hello and world"}

# 验证结果
GET task/_search
{
  "query": {
    "match_phrase": {
      "fielda": "hello & world"
    }
  }
}

二、题目

有一个索引 task3,其中有 fieldafieldbfieldcfielde 现要求对 task3 重建索引,重建后的索引新增一个字段 fieldg 其值是fieldafieldbfieldcfielde 的值拼接而成。

rust 复制代码
# 创建符合条件的 task3 索引,设置 field 字段,并写入数据
PUT task3
{
  "mappings": {
    "properties": {
      "fielda":{
        "type": "keyword"
      },
      "fieldb":{
        "type": "keyword"
      },
      "fieldc":{
        "type": "keyword"
      },
      "fielde":{
        "type": "keyword"
      }
    }
  }
}

POST task3/_bulk
{"index":{}}
{"fielda":"aa","fieldb":"bb","fieldc":"cc","fielde":"dd"}
{"index":{}}
{"fielda":"中华","fieldb":"人民","fieldc":"共和国","fielde":"万岁"}
2.1 考点
  1. 重建索引
  2. 管道
2.2 答案
rust 复制代码
# 预览脚本结果
POST _ingest/pipeline/_simulate
{
  "pipeline": {
    "processors": [
      {
        "script": {
          "lang": "painless",
          "source": """
            ctx['fieldg'] = ctx['fielda'] + ' ' + ctx['fieldb'] + ' '+ctx['fieldc'] + ' ' + ctx['fielde'];
          """
        }
      }
    ]
  },
  "docs": [
    {
      "_source": {
        "fielda":"中华","fieldb":"人民","fieldc":"共和国","fielde":"万岁"
      }
    }
  ]
}

# 定义脚本
PUT _ingest/pipeline/my_pipeline
{
  "processors": [
    {
      "script": {
        "lang": "painless",
        "source": """
            ctx['fieldg'] = ctx['fielda'] + ' ' + ctx['fieldb'] + ' '+ctx['fieldc'] + ' ' + ctx['fielde'];
          """
      }
    }
  ]
}

# 重建索引
POST _reindex
{
  "source": {
    "index": "task3"
  },
  "dest": {
    "index": "task3_new",
    "pipeline": "my_pipeline"
  }
}

# 搜索结果
GET task3_new/_search
相关推荐
大大大大晴天1 小时前
Flink生产问题排障-Kryo serializer scala extensions are not available
大数据·flink
Elasticsearch1 天前
如何使用 Agent Builder 排查 Kubernetes Pod 重启和 OOMKilled 事件
elasticsearch
Elasticsearch2 天前
通用表达式语言 ( CEL ): CEL 输入如何改进 Elastic Agent 集成中的数据收集
elasticsearch
武子康2 天前
大数据-236 离线数仓 - 会员指标验证、DataX 导出与广告业务 ODS/DWD/ADS 全流程
大数据·后端·apache hive
武子康3 天前
大数据-235 离线数仓 - 实战:Flume+HDFS+Hive 搭建 ODS/DWD/DWS/ADS 会员分析链路
大数据·后端·apache hive
DianSan_ERP4 天前
电商API接口全链路监控:构建坚不可摧的线上运维防线
大数据·运维·网络·人工智能·git·servlet
够快云库4 天前
能源行业非结构化数据治理实战:从数据沼泽到智能资产
大数据·人工智能·机器学习·企业文件安全
AI周红伟4 天前
周红伟:智能体全栈构建实操:OpenClaw部署+Agent Skills+Seedance+RAG从入门到实战
大数据·人工智能·大模型·智能体
B站计算机毕业设计超人4 天前
计算机毕业设计Django+Vue.js高考推荐系统 高考可视化 大数据毕业设计(源码+LW文档+PPT+详细讲解)
大数据·vue.js·hadoop·django·毕业设计·课程设计·推荐算法
计算机程序猿学长4 天前
大数据毕业设计-基于django的音乐网站数据分析管理系统的设计与实现(源码+LW+部署文档+全bao+远程调试+代码讲解等)
大数据·django·课程设计