您的位置:首页 > 科技 > IT业 > Elasticsearch 认证模拟题 - 14

Elasticsearch 认证模拟题 - 14

2024/10/5 22:30:25 来源:https://blog.csdn.net/Wolf_xujie/article/details/139549383  浏览:    关键词:Elasticsearch 认证模拟题 - 14

一、题目

在集群中输入以下指令:

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. Mapping 中的 Nested
  2. Query DSL 中的 Nested
1.2 答案
# 新建索引结果,设定正确的字段类型
PUT task10
{"mappings": {"properties": {"brand": {"type": "keyword"},"model": {"type": "keyword"},"features": {"type": "nested","properties": {"type": {"type": "keyword"},"value": {"type": "keyword"}}}}}
}# 向新索引灌入数据
POST _reindex
{"source": {"index": "phones"},"dest": {"index": "task10"}
}# 检查验证结果
GET task10/_search
{"query": {"nested": {"path": "features","query": {"bool": {"must": [{"match": {"features.type": "storage"}},{"match": {"features.value": "12"}}]}}}}
}GET task10/_search
{"query": {"nested": {"path": "features","query": {"bool": {"must": [{"match": {"features.type": "storage"}},{"match": {"features.value": "128"}}]}}}}
}

在这里插入图片描述

二、题目

现有以下文档,请编写一个名为 test_data_stream 数据流满足以下请求:

{"@timestamp": "2099-03-08T11:04:05.000Z","message": "test"
}
  1. 数据流索引的主分片数为 3,副本分片数为 1
  2. 将上述文档填充到数据流中去
2.1 考点
  1. 数据流的建立
  2. 数据流数据的写入
2.2 答案
# 建立索引模板
PUT _index_template/my_template
{"index_patterns": ["test_*"],"data_stream": {},"template": {"settings": {"number_of_replicas": 1,"number_of_shards": 3}},"priority": 500
}# 创建数据流
PUT _data_stream/test_data_stream# 向数据流写入数据
POST test_data_stream/_doc
{"@timestamp": "2099-03-08T11:04:05.000Z","message": "test"
}# 获取数据流中的文档
GET test_data_stream/_search

版权声明:

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

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