Elasticsearch 认证模拟题 - 13

发布于:2024-06-09 ⋅ 阅读:(116) ⋅ 点赞:(0)

一、题目

集群中有索引 task3,用 oaOAOaoA 查询结构是 4 条,使用 dingding 的查询结果是 1 条。通过 reindex 索引 task3task3_new,能够使 task3_new 满足以下查询条件。

  1. 使用 oaOAOaoA0Adingding 查询都能够返回 6 条结果
    后能够使得使用oa、OA、Oa、oA、0A、dingding都是6条。
PUT task3
{
  "settings": {
    "number_of_replicas": 0
  },
  "mappings": {
    "properties": {
      "title": {
        "type": "text"
      }
    }
  }
}

POST task3/_bulk
{"index":{}}
{"title":"oa"}
{"index":{}}
{"title":"OA"}
{"index":{}}
{"title":"Oa"}
{"index":{}}
{"title":"oA"}
{"index":{}}
{"title":"0A"}
{"index":{}}
{"title":"dingding"}
1.1 考点
  1. 分词器
  2. 重建索引
1.2 答案
# 创建索引结构,定义分词器
PUT /task3_new
{
  "settings": {
    "index": {
      "analysis": {
        "analyzer": {
          "synonym_analyzer": {
            "tokenizer": "standard",
            "filter": [
              "synonym"
            ]
          }
        },
        "filter": {
          "synonym": {
            "type": "synonym",
            "synonyms": [
              "oa, OA, Oa, oA, 0A, dingding"
            ]
          }
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "title":{
        "type": "text", 
        "analyzer": "synonym_analyzer"
      }
    }
  }
}

# 重建索引
POST _reindex
{
  "source": {
    "index": "task3"
  },
  "dest": {
    "index": "task3_new"
  }
}

# 验证结果
GET task3_new/_search
{
  "query": {
    "match": {
      "title": "dingding"
    }
  }
}

二、题目

集群上有索引 task9 编写一个查询,并满足以下要求:

  1. abc 字段至少有两个字段匹配中 test 关键字
  2. 对查询结果进行排序,先按照 a 字段进行降序排序,再按照 _socre 进行升序排序
  3. a 字段的返回结果高亮显示,前标签是 <h1>,后标签是 </h1>
PUT task9
{
  "mappings": {
    "properties": {
      "a":{
        "type": "keyword"
      }
    }
  }
}

POST task9/_bulk
{"index":{}}
{"a":"test", "b":"b", "c":"test"}
{"index":{}}
{"a":"a", "b":"test", "c":"c"}
{"index":{}}
{"a":"a", "b":"test", "c":"test"}
2.1 考点
  1. Boolean
  2. Sort
  3. Highlighting
2.2 答案
POST task9/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "term": {
            "a": "test"
          }
        },
        {
          "term": {
            "b": "test"
          }
        },
        {
          "term": {
            "c": "test"
          }
        }
      ],
      "minimum_should_match": 2
    }
  },
  "sort": [
    {
      "a": "desc"
    },
    {
      "_score": "asc"
    }
  ],
  "highlight": {
    "fields": {
      "a": {
        "pre_tags": [
          "<h1>"
        ],
        "post_tags": [
          "</h1>"
        ]
      }
    }
  }
}

在这里插入图片描述


网站公告

今日签到

点亮在社区的每一天
去签到