一、题目
为一个索引,按要求设置以下 dynamic Mapping
- 一切 text 类型的字段,类型全部映射成 keyword
- 一切以 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.2 答案
# 建立别名
POST _aliases
{
"actions": [
{
"add": {
"index": "movies",
"alias": "movies_alias",
"filter": {
"bool": {
"filter": [
{
"range": {
"score": {
"gte": 3
}
}
}
]
}
}
}
}
]
}
# 用别名检索
GET movies_alias/_search