一、题目
使用异步查询 task1 索引,并且 找到 miantable_name
字段值为 name8 的文档
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,同时满足以下要求
- 增加一个整形字段,将索引 a_index 中的
name
字段的字符串长度,计算后写入 - 将 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 考点
- reindex
- 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