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"
    }
    }
  ]
}
相关推荐
HerayChen20 分钟前
HbuildderX运行到手机或模拟器的Android App基座识别不到设备 mac
android·macos·智能手机
顾北川_野21 分钟前
Android 手机设备的OEM-unlock解锁 和 adb push文件
android·java
hairenjing112323 分钟前
在 Android 手机上从SD 卡恢复数据的 6 个有效应用程序
android·人工智能·windows·macos·智能手机
小黄人软件1 小时前
android浏览器源码 可输入地址或关键词搜索 android studio 2024 可开发可改地址
android·ide·android studio
dj15402252031 小时前
group_concat配置影响程序出bug
android·bug
周全全2 小时前
MySQL报错解决:The user specified as a definer (‘root‘@‘%‘) does not exist
android·数据库·mysql
- 羊羊不超越 -2 小时前
App渠道来源追踪方案全面分析(iOS/Android/鸿蒙)
android·ios·harmonyos
晨欣2 小时前
Elasticsearch和Lucene之间是什么关系?(ChatGPT回答)
elasticsearch·chatgpt·lucene
wk灬丨3 小时前
Android Kotlin Flow 冷流 热流
android·kotlin·flow