Elasticsearch 认证模拟题 - 15

一、题目

原索引 task1 的字段 title 字段包含单词 The,查询 the 可以查出 1200 篇文档。重建 task1 索引为 task1_new,重建后的索引, title 字段查询 the 单词,不能匹配到任何文档。

PUT task1
{
  "mappings": {
    "properties": {
      "title": {
        "type": "text"
      }
    }
  }
}

# 灌入数据
POST task1/_bulk
{"index": {}}
{"title": "the name"}
{"index": {}}
{"title": "the sex"}
{"index": {}}
{"title": "The age"}
{"index": {}}
{"title": "height"}

# 检查查询结果
GET task1/_search
{
  "query": {
    "match": {
      "title": "the"
    }
  }
}
1.1 考点
  1. 分词器里面的停用词
1.2 答案
# 新建索引结构,自定义分词器
PUT task1_new
{
  "settings": {
    "analysis": {
      "analyzer": {
        "my_custom_analyzer": { 
          "char_filter": [],
          "tokenizer": "standard",
          "filter": [
            "my_custom_stop_words_filter"
          ]
        }
      },
      "filter": {
        "my_custom_stop_words_filter": {
          "type": "stop",
          "ignore_case": true,
          "stopwords": ["the" ]
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "title": {
        "type": "text",
        "analyzer": "my_custom_analyzer"
      }
    }
  }
}

# 向新索引灌入数据
POST _reindex
{
  "source": {
    "index": "task1"
  },
  "dest": {
    "index": "task1_new"
  }
}

# 检查查询结果
GET task1_new/_search
{
  "query": {
    "match": {
      "title": "The"
    }
  }
}

二、题目

索引 kibana_sample_data_flights 包含了大量的航班信息,以此写出满足以下条件的查询语句:

  1. 对美国的航班信息按照城市分组,找出平均航班延迟时间最高的城市

光看这个题目是有点不知道这个条件是啥,这里将这个条件拆分一下

  1. 要求目的地国家(DestCountry)为 美国(US
  2. 航班发生了延迟(FlightDelaytrue
  3. 找出每个城市的航班平均延迟时间(FlightDelayMin
  4. 找到航班延迟时间最大的城市
{
  "FlightNum": "XLL6LDF",
  "DestCountry": "ZA",
  "OriginWeather": "Thunder & Lightning",
  "OriginCityName": "Jebel Ali",
  "AvgTicketPrice": 642.5951482867853,
  "DistanceMiles": 3942.7713488567097,
  "FlightDelay": false,
  "DestWeather": "Damaging Wind",
  "Dest": "OR Tambo International Airport",
  "FlightDelayType": "No Delay",
  "OriginCountry": "AE",
  "dayOfWeek": 4,
  "DistanceKilometers": 6345.275413654453,
  "timestamp": "2024-05-10T06:09:09",
  "DestLocation": {
    "lat": "-26.1392",
    "lon": "28.246"
  },
  "DestAirportID": "JNB",
  "Carrier": "Logstash Airways",
  "Cancelled": false,
  "FlightTimeMin": 302.15597207878346,
  "Origin": "Al Maktoum International Airport",
  "OriginLocation": {
    "lat": "24.896356",
    "lon": "55.161389"
  },
  "DestRegion": "SE-BD",
  "OriginAirportID": "DWC",
  "OriginRegion": "SE-BD",
  "DestCityName": "Johannesburg",
  "FlightTimeHour": 5.035932867979724,
  "FlightDelayMin": 0
}
2.1 考点
  1. Boolean
  2. 聚合
2.2 答案
GET kibana_sample_data_flights/_search
{
  "size": 0, 
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "DestCountry": {
              "value": "US"
            }
          }
        },
        {
          "term": {
            "FlightDelay": {
              "value": "true"
            }
          }
        }
      ]
    }
  },
  "aggs": {
    "DestCityName_bucket": {
       "terms": { "field": "DestCityName" },
       "aggs": {
          "avg_FlightDelayMin": { "avg": { "field": "FlightDelayMin" } }
       }
    },
    "max_monthly_sales": {
      "max_bucket": {
        "buckets_path": "DestCityName_bucket>avg_FlightDelayMin" 
      }
    }
  }
}

在这里插入图片描述

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值