当前位置: 首页 > news >正文

Elasticsearch 认证模拟题 - 8

一、题目

在集群中输入以下指令:

PUT phones/_doc/1
{"brand":"Samsumg","model":"Galaxy S9+","features":[{"type":"os", "value":"Android"},{"type":"storage", "value":"64"},{"type":"camera_resolution", "value":"12"}]
}
PUT phones/_doc/2
{"brand":"Apple","model":"iPhone XR","features":[{"type":"os", "value":"Apple 10s"},{"type":"storage", "value":"128"},{"type":"camera_resolution", "value":"12"}]
}GET /phones/_search
{"query": {"bool": {"must": [{"match": {"features.type": "storage"}},{"match": {"features.value": "12"}}]}}
}

注意查询语句的查询结果,尽管它们的 type 字段值为 storage 时,value 字段的值都不等于 12,不知道为什么,特征数组的类型和值对象之间的关系丢失了。

现要求新建一个索引 task10,能够保持特征数组中对象和值之间的关系。并将上述两个文档写入到 task10 中,然后编写一个查询 type 字段值为 storage 时,value 字段的值等于 12 的 查询。此时上面两个文档都应该不在你的查询范围内。

1.1 考点

讲真的,刚看这个题属实懵了,印象中确实有这个知识点,但是死活找不到!!!!

  1. nested 字段
  2. nested 查询
1.2 答案
# 创建索引
PUT task10
{"mappings": {"properties": {"brand": {"type": "keyword"},"model": {"type": "keyword"},"features": {"type": "nested", "properties": {"type": {"type" : "keyword"},"value": {"type": "keyword"}}}}}
}# 写入数据
POST task10/_bulk
{"index":{}}
{"brand":"Samsumg","model":"Galaxy S9+","features":[{"type":"os","value":"Android"},{"type":"storage","value":"64"},{"type":"camera_resolution","value":"12"}]}
{"index":{}}
{"brand":"Apple","model":"iPhone XR","features":[{"type":"os","value":"Apple 10s"},{"type":"storage","value":"128"},{"type":"camera_resolution","value":"12"}]}
{"index":{}}
{"brand":"Apple","model":"iPhone XR","features":[{"type":"os","value":"Apple 10s"},{"type":"storage","value":"12"},{"type":"camera_resolution","value":"12"}]}# 查询
GET /task10/_search
{"query": {"nested": {"path": "features","query": {"bool": {"must": [{"match": {"features.type": "storage"}},{"match": {"features.value": "12"}}]}}}}
}

二、题目

二个索引,主索引是 miantable,用户索引是 usertablemiantable 通过 userid 关联 usertableusertable 总共有4个用户数据。

要求:

  1. 新建表 miantable_v1miantable_v1 包含 miantable 的所有字段
  2. miantable_v1 新增 userName ,通过 useridusertable 索引中 userName 关联到 miantable_v1
# 创建索引结构
PUT usertable
{"mappings": {"properties": {"userid": {"type": "integer"},"username": {"type": "keyword"}}}
}PUT miantable
{"mappings": {"properties": {"f_crm_id": {"type": "integer"},"miantable_name": {"type": "keyword"},"userid": {"type": "integer"}}}
}# 批量写入数据
POST usertable/_bulk
{"index":{"_id":1}}
{"userid":1, "username":"tom"}
{"index":{"_id":2}}
{"userid":2, "username":"white"}
{"index":{"_id":3}}
{"userid":3, "username":"john"}
{"index":{"_id":4}}
{"userid":4, "username":"green"}POST miantable/_bulk
{"index":{"_id":1}}
{"f_crm_id":1, "miantable_name":"name1", "userid":1}
{"index":{"_id":2}}
{"f_crm_id":2, "miantable_name":"name2", "userid":2}
{"index":{"_id":3}}
{"f_crm_id":3, "miantable_name":"name3", "userid":3}
{"index":{"_id":4}}
{"f_crm_id":4, "miantable_name":"name4", "userid":1}
{"index":{"_id":5}}
{"f_crm_id":5, "miantable_name":"name5", "userid":1}
{"index":{"_id":6}}
{"f_crm_id":6, "miantable_name":"name6", "userid":2}
{"index":{"_id":7}}
{"f_crm_id":7, "miantable_name":"name7", "userid":2}
{"index":{"_id":8}}
{"f_crm_id":8, "miantable_name":"name8", "userid":4}
{"index":{"_id":9}}
{"f_crm_id":9, "miantable_name":"name9", "userid":4}
{"index":{"_id":10}}
{"f_crm_id":10, "miantable_name":"name10", "userid":1}
{"index":{"_id":11}}
{"f_crm_id":11, "miantable_name":"name11", "userid":2}
{"index":{"_id":12}}
{"f_crm_id":12, "miantable_name":"name12", "userid":5}
2.1 考点
  1. Enrich
  2. 重建索引

这里我认为直接看 enrich 的三个例子是最快能理解的

2.2 答案
# 新建enrich 策略
PUT /_enrich/policy/my-policy
{"match": {"indices": "usertable","match_field": "userid","enrich_fields": ["username"]}
}# 执行策略
POST /_enrich/policy/my-policy/_execute# 建立管道
PUT _ingest/pipeline/my-pipeline
{"processors" : [{"enrich": {"policy_name": "my-policy","field": "userid","target_field": "add_field","max_matches": "1"}},{"rename": {"field": "add_field.username","target_field": "username","ignore_failure": true}},{"remove": {"field": "add_field","ignore_failure": true}}]
}# 重建索引
POST _reindex
{"source": {"index": "miantable"},"dest": {"index": "miantable_v1","pipeline": "my-pipeline"}
}# 查询结果
GET miantable_v1/_search
http://www.lryc.cn/news/366607.html

相关文章:

  • 【Postman接口测试】第四节.Postman接口测试项目实战(中)
  • Hadoop的Windows环境准备
  • 使用亮数据代理IP爬取PubMed文章链接和邮箱地址
  • electron调用dll时应用程序闪退
  • 单片机原理及技术(三)—— AT89S51单片机(二)(C51编程)
  • 摄影店展示服务预约小程序的作用是什么
  • 【数据分析基础】实验一 Python运算符、内置函数、序列基本用法
  • 【Redis】构建强韧的远程Redis连接与端口保障机制完美指南
  • Flowable项目启动报错#java.time.LocalDateTime cannot be cast to java.lang.String
  • 《数字电路》
  • STM32F103 点亮LED闪烁与仿真
  • 阿里云服务器发送邮件失败 Could not connect to SMTP host: smtp.xxx.com, port: 465;
  • Socket编程权威指南(二)完美掌握TCP流式协议及Socket编程的recv()和send()
  • 当C++的static遇上了继承
  • Three.js中的Raycasting技术:实现3D场景交互事件的Raycaster详解
  • 5 分钟内构建一个简单的基于 Python 的 GAN
  • 智能硬件产品中常用的参数存储和管理方案
  • SwiftUI中Mask修饰符的理解与使用
  • 全光网络与传统网络架构的对比分析
  • stack overflow复现
  • mybatis使用笔记
  • 学习笔记——路由网络基础——路由概述
  • 在量子计算时代,大数据技术将面临哪些挑战和机遇?
  • 怎么换自己手机的ip地址
  • 搭建 Langchain-Chatchat 详细过程
  • C++期末复习
  • 2005-2022年各省居民人均消费支出数据(无缺失)
  • swaggerHole:针对swaggerHub的公共API安全扫描工具
  • 【Rust】——面向对象设计模式的实现
  • C#朗读语音