欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 时评 > Elasticsearch 认证模拟题 - 18

Elasticsearch 认证模拟题 - 18

2025/9/16 7:11:46 来源:https://blog.csdn.net/Wolf_xujie/article/details/139638308  浏览:    关键词:Elasticsearch 认证模拟题 - 18

一、题目

为一个索引,按要求设置以下 dynamic Mapping

  1. 一切 text 类型的字段,类型全部映射成 keyword
  2. 一切以 int_ 开头命名的字段,类型都设置成 integer
1.1 考点

字段的动态映射

1.2 答案
# 创建索引和索引模板
PUT my_index
{"mappings": {"dynamic_templates": [{"integer": {"match": "int_*","mapping": {"type": "integer"}}},{"text": {"match_mapping_type": "string","mapping": {"type": "keyword"}}}]}
}# 写入数据
POST my_index/_bulk
{"index":{}}
{"text":"天安门广场", "int_value":23}
{"index":{}}
{"cont":"好看的小说", "int_value":50.0}
{"index":{}}
{"cont":"晚上值班很痛苦", "int_value":88.8}检查索引结构
GET my_index/_mapping

在这里插入图片描述

二、题目

movies 索引设定一个别名,默认查询只返回 score 字段 大于 3 的电影

# 创建索引
PUT movies
{"mappings": {"properties": {"name": {"type": "keyword"},"score": {"type": "float"}}}
}# 写入数据
POST movies/_bulk
{"index":{}}
{"name":"百万雄师过大江","score":5}
{"index":{}}
{"name":"陆小凤传奇","score":4}
{"index":{}}
{"name":"七宗罪","score":3}
{"index":{}}
{"name":"华尔街之狼","score":2.1}
1.1 考点
  1. 索引别名
1.2 答案
# 建立别名
POST _aliases
{"actions": [{"add": {"index": "movies","alias": "movies_alias","filter": {"bool": {"filter": [{"range": {"score": {"gte": 3}}}]}}}}]
}# 用别名检索
GET movies_alias/_search

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词