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
相关推荐
阿里云大数据AI技术12 小时前
大数据公有云市场第一,阿里云占比47%!
大数据
Lx35216 小时前
Hadoop容错机制深度解析:保障作业稳定运行
大数据·hadoop
muyun280020 小时前
Docker 下部署 Elasticsearch 8 并集成 Kibana 和 IK 分词器
elasticsearch·docker·容器
T062051421 小时前
工具变量-5G试点城市DID数据(2014-2025年
大数据
向往鹰的翱翔21 小时前
BKY莱德因:5大黑科技逆转时光
大数据·人工智能·科技·生活·健康医疗
鸿乃江边鸟1 天前
向量化和列式存储
大数据·sql·向量化
IT毕设梦工厂1 天前
大数据毕业设计选题推荐-基于大数据的客户购物订单数据分析与可视化系统-Hadoop-Spark-数据可视化-BigData
大数据·hadoop·数据分析·spark·毕业设计·源码·bigdata
java水泥工1 天前
基于Echarts+HTML5可视化数据大屏展示-白茶大数据溯源平台V2
大数据·echarts·html5
广州腾科助你拿下华为认证1 天前
华为考试:HCIE数通考试难度分析
大数据·华为
在未来等你1 天前
Elasticsearch面试精讲 Day 17:查询性能调优实践
大数据·分布式·elasticsearch·搜索引擎·面试