Elasticsearch 认证模拟题 - 8

2024-06-08 02:12

本文主要是介绍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

这篇关于Elasticsearch 认证模拟题 - 8的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1040952

相关文章

SpringSecurity6.0 如何通过JWTtoken进行认证授权

《SpringSecurity6.0如何通过JWTtoken进行认证授权》:本文主要介绍SpringSecurity6.0通过JWTtoken进行认证授权的过程,本文给大家介绍的非常详细,感兴趣... 目录项目依赖认证UserDetailService生成JWT token权限控制小结之前写过一个文章,从S

Elasticsearch 在 Java 中的使用教程

《Elasticsearch在Java中的使用教程》Elasticsearch是一个分布式搜索和分析引擎,基于ApacheLucene构建,能够实现实时数据的存储、搜索、和分析,它广泛应用于全文... 目录1. Elasticsearch 简介2. 环境准备2.1 安装 Elasticsearch2.2 J

springboot security使用jwt认证方式

《springbootsecurity使用jwt认证方式》:本文主要介绍springbootsecurity使用jwt认证方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地... 目录前言代码示例依赖定义mapper定义用户信息的实体beansecurity相关的类提供登录接口测试提供一

SpringSecurity 认证、注销、权限控制功能(注销、记住密码、自定义登入页)

《SpringSecurity认证、注销、权限控制功能(注销、记住密码、自定义登入页)》SpringSecurity是一个强大的Java框架,用于保护应用程序的安全性,它提供了一套全面的安全解决方案... 目录简介认识Spring Security“认证”(Authentication)“授权” (Auth

一文详解kafka开启kerberos认证的完整步骤

《一文详解kafka开启kerberos认证的完整步骤》这篇文章主要为大家详细介绍了kafka开启kerberos认证的完整步骤,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录一、kerberos安装部署二、准备机器三、Kerberos Server 安装1、配置krb5.con

ElasticSearch+Kibana通过Docker部署到Linux服务器中操作方法

《ElasticSearch+Kibana通过Docker部署到Linux服务器中操作方法》本文介绍了Elasticsearch的基本概念,包括文档和字段、索引和映射,还详细描述了如何通过Docker... 目录1、ElasticSearch概念2、ElasticSearch、Kibana和IK分词器部署

java如何通过Kerberos认证方式连接hive

《java如何通过Kerberos认证方式连接hive》该文主要介绍了如何在数据源管理功能中适配不同数据源(如MySQL、PostgreSQL和Hive),特别是如何在SpringBoot3框架下通过... 目录Java实现Kerberos认证主要方法依赖示例续期连接hive遇到的问题分析解决方式扩展思考总

Java实现Elasticsearch查询当前索引全部数据的完整代码

《Java实现Elasticsearch查询当前索引全部数据的完整代码》:本文主要介绍如何在Java中实现查询Elasticsearch索引中指定条件下的全部数据,通过设置滚动查询参数(scrol... 目录需求背景通常情况Java 实现查询 Elasticsearch 全部数据写在最后需求背景通常情况下

Java操作ElasticSearch的实例详解

《Java操作ElasticSearch的实例详解》Elasticsearch是一个分布式的搜索和分析引擎,广泛用于全文搜索、日志分析等场景,本文将介绍如何在Java应用中使用Elastics... 目录简介环境准备1. 安装 Elasticsearch2. 添加依赖连接 Elasticsearch1. 创

浅析Spring Security认证过程

类图 为了方便理解Spring Security认证流程,特意画了如下的类图,包含相关的核心认证类 概述 核心验证器 AuthenticationManager 该对象提供了认证方法的入口,接收一个Authentiaton对象作为参数; public interface AuthenticationManager {Authentication authenticate(Authenti