当前位置: 首页 > 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

相关文章:

  • 正则限制字符串的长度必须是n的倍数
  • c++替换字符或字符串函数
  • 【爬虫】使用Python爬取百度学术页面的标题、作者、摘要和关键词
  • 详解大模型微调数据集构建方法(持续更新)
  • ant design form表单动态增减表单项Form.List选中Select值后更新相关联Select选项
  • 你使用过哪些性能分析工具来优化Java程序?
  • spring 事务隔离级别
  • [手游] 口袋妖怪肉鸽宝可梦肉鸽
  • 烧写uboot、linux镜像、根文件系统到开发板
  • 数据挖掘--引论
  • 基于zyyo主页与無名の主页合并二改,一款适合新手的个人主页
  • c++ 简单的日志类 CCLog
  • SpringMVC:拦截器(Interceptor)
  • Python | 排队取奶茶
  • 老旧机子装LINUX——xubuntu
  • Debian下无root权限使用Python访问Oracle
  • Effective Java 笔记(一)
  • Intervention/image 图片处理扩展包的安装和使用
  • JavaScript 事件——“事件类型”中“HTML5事件”的注意要点
  • leetcode388. Longest Absolute File Path
  • Netty+SpringBoot+FastDFS+Html5实现聊天App(六)
  • PHP 程序员也能做的 Java 开发 30分钟使用 netty 轻松打造一个高性能 websocket 服务...
  • spring cloud gateway 源码解析(4)跨域问题处理
  • ⭐ Unity 开发bug —— 打包后shader失效或者bug (我这里用Shader做两张图片的合并发现了问题)
  • 从0到1:PostCSS 插件开发最佳实践
  • 第三十一到第三十三天:我是精明的小卖家(一)
  • 关于 Linux 进程的 UID、EUID、GID 和 EGID
  • 罗辑思维在全链路压测方面的实践和工作笔记
  • 前端面试之闭包
  • 深度学习在携程攻略社区的应用
  • “十年磨一剑”--有赞的HBase平台实践和应用之路 ...
  • PostgreSQL之连接数修改
  • 你学不懂C语言,是因为不懂编写C程序的7个步骤 ...
  • ## 临床数据 两两比较 加显著性boxplot加显著性
  • #07【面试问题整理】嵌入式软件工程师
  • #ifdef 的技巧用法
  • #if等命令的学习
  • #QT项目实战(天气预报)
  • #免费 苹果M系芯片Macbook电脑MacOS使用Bash脚本写入(读写)NTFS硬盘教程
  • (1)无线电失控保护(二)
  • (2024,Vision-LSTM,ViL,xLSTM,ViT,ViM,双向扫描)xLSTM 作为通用视觉骨干
  • (4)通过调用hadoop的java api实现本地文件上传到hadoop文件系统上
  • (PyTorch)TCN和RNN/LSTM/GRU结合实现时间序列预测
  • (附源码)spring boot网络空间安全实验教学示范中心网站 毕业设计 111454
  • (附源码)计算机毕业设计SSM基于java的云顶博客系统
  • (黑马点评)二、短信登录功能实现
  • (求助)用傲游上csdn博客时标签栏和网址栏一直显示袁萌 的头像
  • (三分钟)速览传统边缘检测算子
  • (五)IO流之ByteArrayInput/OutputStream
  • (续)使用Django搭建一个完整的项目(Centos7+Nginx)
  • (一)kafka实战——kafka源码编译启动
  • (一)VirtualBox安装增强功能
  • (译) 函数式 JS #1:简介
  • (转)Linux NTP配置详解 (Network Time Protocol)
  • (转)编辑寄语:因为爱心,所以美丽