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
  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值