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

相关文章

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

基于MySQL Binlog的Elasticsearch数据同步实践

一、为什么要做 随着马蜂窝的逐渐发展,我们的业务数据越来越多,单纯使用 MySQL 已经不能满足我们的数据查询需求,例如对于商品、订单等数据的多维度检索。 使用 Elasticsearch 存储业务数据可以很好的解决我们业务中的搜索需求。而数据进行异构存储后,随之而来的就是数据同步的问题。 二、现有方法及问题 对于数据同步,我们目前的解决方案是建立数据中间表。把需要检索的业务数据,统一放到一张M

机试算法模拟题 服务中心选址

题目描述 一个快递公司希望在一条街道建立新的服务中心。公司统计了该街道中所有区域在地图上的位置,并希望能够以此为依据为新的服务中心选址:使服务中心到所有区域的距离的总和最小。 给你一个数组positions,其中positions[i] = [left, right] 表示第 i 个区域在街道上的位置,其中left代表区域的左侧的起点,right代表区域的右侧终点,假设服务中心的位置为loca

【Kubernetes】K8s 的安全框架和用户认证

K8s 的安全框架和用户认证 1.Kubernetes 的安全框架1.1 认证:Authentication1.2 鉴权:Authorization1.3 准入控制:Admission Control 2.Kubernetes 的用户认证2.1 Kubernetes 的用户认证方式2.2 配置 Kubernetes 集群使用密码认证 Kubernetes 作为一个分布式的虚拟

【Shiro】Shiro 的学习教程(二)之认证、授权源码分析

目录 1、背景2、相关类图3、解析3.1、加载、解析阶段3.2、认证阶段3.3、授权阶段 1、背景 继上节代码,通过 debug 进行 shiro 源码分析。 2、相关类图 debug 之前,先了解下一些类的结构图: ①:SecurityManager:安全管理器 DefaultSecurityManager: RememberMeManager:实现【记住我】功能

ElasticSearch的DSL查询⑤(ES数据聚合、DSL语法数据聚合、RestClient数据聚合)

目录 一、数据聚合 1.1 DSL实现聚合 1.1.1 Bucket聚合  1.1.2 带条件聚合 1.1.3 Metric聚合 1.1.4 总结 2.1 RestClient实现聚合 2.1.1 Bucket聚合 2.1.2 带条件聚合 2.2.3 Metric聚合 一、数据聚合 聚合(aggregations)可以让我们极其方便的实现对数据的统计、分析、运算。例如: