Elasticsearch 认证模拟题 - 9

一、题目

在集群上有两个索引 index_aindex_bindex_a 中有字段 field_a ,没有 field_a_descindex_b 中有 field_afield_a_desc 。其中 index_b 中共有 10 条数据。

要求:

  1. reindex 一个索引 index_c ,要求包含 index_a 中的所有数据
  2. index_c 中新增 field_a_desc 字段,且 field_a 的值与 index_b 索引中 field_a 的值相同。
rust 复制代码
# 创建索引结构
PUT index_a
{
  "mappings": {
    "properties": {
      "field_a":{
        "type":"keyword"
      },
      "field_a-01":{
        "type": "keyword"
      }
    }
  }
}

PUT index_b
{
  "mappings": {
    "properties": {
      "field_a":{
        "type": "keyword"
      },
      "field_a_desc":{
        "type": "keyword"
      }
    }
  }
}

# 索引数据导入
POST index_a/_bulk
{"index":{"_id":1}}
{"field_a":"a001","field_a_01":"usera01"}
{"index":{"_id":2}}
{"field_a":"a002","field_a_01":"usera02"}
{"index":{"_id":3}}
{"field_a":"a003","field_a_01":"usera03"}
{"index":{"_id":4}}
{"field_a":"a001","field_a_01":"usera011"}
{"index":{"_id":5}}
{"field_a":"a002","field_a_01":"usera012"}
{"index":{"_id":6}}
{"field_a":"a003","field_a_01":"usera013"}
{"index":{"_id":7}}
{"field_a":"a007","field_a_01":"usera021"}
{"index":{"_id":8}}
{"field_a":"a008","field_a_01":"usera022"}
{"index":{"_id":9}}
{"field_a":"a009","field_a_01":"usera023"}
{"index":{"_id":10}}
{"field_a":"a010","field_a_01":"usera031"}
{"index":{"_id":11}}
{"field_a":"a008","field_a_01":"usera032"}
{"index":{"_id":12}}
{"field_a":"a009","field_a_01":"usera033"}

POST index_b/_bulk
{"index":{"_id":1}}
{"field_a":"a001","field_a_desc":"money_01"}
{"index":{"_id":2}}
{"field_a":"a002","field_a_desc":"money_02"}
{"index":{"_id":3}}
{"field_a":"a003","field_a_desc":"money_03"}
{"index":{"_id":4}}
{"field_a":"a004","field_a_desc":"money_04"}
{"index":{"_id":5}}
{"field_a":"a005","field_a_desc":"money_05"}
{"index":{"_id":6}}
{"field_a":"a006","field_a_desc":"money_06"}
{"index":{"_id":7}}
{"field_a":"a007","field_a_desc":"money_07"}
{"index":{"_id":8}}
{"field_a":"a008","field_a_desc":"money_08"}
{"index":{"_id":9}}
{"field_a":"a009","field_a_desc":"money_09"}
{"index":{"_id":10}}
{"field_a":"a010","field_a_desc":"money_10"}
1.1 考点
  1. Enrich
  2. 重建索引
1.2 答案
rust 复制代码
# 新建enrich 策略
PUT /_enrich/policy/my-policy
{
  "match": {
    "indices": "index_b",
    "match_field": "field_a",
    "enrich_fields": ["field_a_desc"]
  }
}

# 执行策略
POST /_enrich/policy/my-policy/_execute

# 建立管道
PUT /_ingest/pipeline/my_pipeline
{
  "processors" : [
    {
      "enrich" : {
        "policy_name": "my-policy",
        "field" : "field_a",
        "target_field": "add_field",
        "max_matches": "1"
      }
    },
    {
      "rename": {
        "field": "add_field.field_a_desc",
        "target_field": "field_a_desc",
        "ignore_failure": true
      }
    },
    {
      "remove": {
        "field": "add_field",
        "ignore_failure": true
      }
    }
  ]
}

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

# 查询结果
GET index_c/_search
{
  "query": {
    "match_all": {}
  }
}

二、题目

在集群上有一个索引 task3,搜索满足以下要求:

  1. 字段 abc 三个字段任意一个字段,可以搜到文本 cake mix
  2. highlight 字段 d,加标签
  3. sort 字段 e 正序,_score 降序
rust 复制代码
PUT task3
{
  "mappings": {
    "properties": {
      "a":{
        "type": "text"
      },
      "b":{
        "type": "text"
      },
      "c":{
        "type": "text"
      },
      "d":{
        "type":"text"
      },
      "e":{
        "type": "keyword"
      }
    }
  }
}

POST task3/_bulk
{"index": {}}
{"a":"cake mix", "b":"a", "c":"a", "d":"cake mix", "e":"1"}
{"index": {}}
{"a":"b", "b":"b", "c":"b", "d":"cake mix", "e":"2"}
{"index": {}}
{"a":"c", "b":"c", "c":"cake mix", "d":"cake mix", "e":"3"}
2.1 考点
  1. Multi-match
  2. highlight
  3. sort
2.2 答案
rust 复制代码
GET task3/_search
{
  "query": {
    "multi_match": {
      "query": "cake mix",
      "fields": ["a", "b", "c"]
    }
  },
  "highlight": {
    "pre_tags" : ["<tag1>"],
    "post_tags" : ["</tag1>"],
    "fields" : {
      "d": {}
    }
  },
  "sort": [
    {
      "e": {
        "order": "asc"
      }
    },
    {
      "_score": {
      "order": "desc"
    }
    }
  ]
}
相关推荐
mmsx1 小时前
android sqlite 数据库简单封装示例(java)
android·java·数据库
VinciYan4 小时前
基于Jenkins+Docker的自动化部署实践——整合Git与Python脚本实现远程部署
python·ubuntu·docker·自动化·jenkins·.net·运维开发
it噩梦4 小时前
es 中 terms set 使用
大数据·elasticsearch
众拾达人4 小时前
Android自动化测试实战 Java篇 主流工具 框架 脚本
android·java·开发语言
吃着火锅x唱着歌5 小时前
PHP7内核剖析 学习笔记 第四章 内存管理(1)
android·笔记·学习
_Shirley6 小时前
鸿蒙设置app更新跳转华为市场
android·华为·kotlin·harmonyos·鸿蒙
喝醉酒的小白6 小时前
Elasticsearch 配置文件
大数据·elasticsearch·搜索引擎
jwensh7 小时前
【Jenkins】Declarative和Scripted两种脚本模式有什么具体的区别
运维·前端·jenkins
hedalei8 小时前
RK3576 Android14编译OTA包提示java.lang.UnsupportedClassVersionError问题
android·android14·rk3576
锋风Fengfeng8 小时前
安卓多渠道apk配置不同签名
android