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

相关推荐

  1. Elasticsearch 认证模拟 - 10

    2024-06-11 21:30:03       31 阅读
  2. Elasticsearch 认证模拟 - 12

    2024-06-11 21:30:03       35 阅读
  3. Elasticsearch 认证模拟 - 6

    2024-06-11 21:30:03       27 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-06-11 21:30:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-06-11 21:30:03       100 阅读
  3. 在Django里面运行非项目文件

    2024-06-11 21:30:03       82 阅读
  4. Python语言-面向对象

    2024-06-11 21:30:03       91 阅读

热门阅读

  1. python爬虫爬取豆瓣TOP250用csv文件

    2024-06-11 21:30:03       30 阅读
  2. LINUX 查找文件

    2024-06-11 21:30:03       32 阅读
  3. C++中的解释器模式

    2024-06-11 21:30:03       35 阅读
  4. 乘船过河(ship)

    2024-06-11 21:30:03       34 阅读
  5. Canny边缘算法总结(基于C语言)

    2024-06-11 21:30:03       35 阅读