Elasticsearch 认证模拟题 - 19

一、题目

使用异步查询 task1 索引,并且 找到 miantable_name 字段值为 name8 的文档

1.1 考点
  1. 异步搜索
1.2 答案
POST task1/_async_search
{
  "query": {
    "term": {
      "miantable_name": {
        "value": "name8"
      }
    }
  }
}

# 这里的 id 是文档中例子的,数据量太少。。。构造不出来一个异步搜索
GET /_async_search/FmRldE8zREVEUzA2ZVpUeGs2ejJFUFEaMkZ5QTVrSTZSaVN3WlNFVmtlWHJsdzoxMDc=

二、题目

给一个索引 a_index,要求创建索引 b_index,通过 reindex,将索引 a_index 中的文档写入索引 b_index,同时满足以下要求

  1. 增加一个整形字段,将索引 a_index 中的 name 字段的字符串长度,计算后写入
  2. 将 A 文档中的字符串以 分隔后,写入索引 b_index 中的数组字段中
PUT a_index
{
  "mappings": {
    "properties": {
      "name":{"type":"keyword"},
      "horry":{"type":"keyword"}
    }
  }
}

POST a_index/_bulk
{"index":{}}
{"name":"xiaozhang","horry":"pingpang;basketball;football"}
{"index":{}}
{"name":"mingyi","horry":"glof;basketball;football"}
{"index":{}}
{"name":"mytx","horry":"glof;basketball;ticket"}
{"index":{}}
{"name":"test","horry":"glof"}
2.1 考点
  1. reindex
  2. Ingest pipelines
    2.1 Script
    2.2 Split
    2.3 Rename
2.2 答案
# 获取某个字段长度的脚本测试
POST _ingest/pipeline/_simulate
{
  "pipeline": {
    "processors": [
      {
        "script": {
          "lang": "painless",
          "source": """
            ctx['name-length'] = ctx['name'].length();
          """
        }
      }
    ]
  },
  "docs": [
    {
      "_source": {
        "name":"teswert"
      }
    }
  ]
}

# 创建 pipeline
PUT _ingest/pipeline/my_pipeline
{
  "processors": [
    {
      "split": {
        "field": "horry",
        "target_field": "horry-array",
        "separator": ";",
        "ignore_missing": true
      }
    },
    {
      "script": {
        "lang": "painless",
        "source": """
            ctx['name-length'] = ctx['name'].length();
          """
      }
    },
    {
      "remove": {
        "field": [
          "horry"
        ]
      }
    }
  ]
}

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

# 结果检查
GET b_index/_search

在这里插入图片描述

  • 6
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值