[ECE]模拟试题-2
创始人
2024-05-11 16:32:43
0
  1. 在cluster1上有一task1索引,请编写一个查询并满足以下要求: runtime fields+range aggs.
    ● 定义一个名为a的运行时字段,通过a字段实现以下聚合(a字段的值等于b字段减去c字段)
    ● 聚合a值小于-2的文档
    ● 聚合-5到5之间的文档
    ● 聚合大于5的文档
    ● 建立测试索引
PUT task1
{"settings": {"number_of_replicas": 0,"number_of_shards": 1,"index.routing.allocation.require.my_node_type": "hot"},"mappings": {"properties": {"b": {"type": "long"},"c": {"type": "long"}}}
}POST task1/_bulk
{"index":{"_id":1}}
{"b":5,"c":6}
{"index":{"_id":2}}
{"b":5,"c":1}
{"index":{"_id":3}}
{"b":8,"c":1}
{"index":{"_id":4}}
{"b":5,"c":8}
PUT task1/_mapping
{"runtime":{"a":{"type":"long","script":{"source":"emit(doc['b'].value - doc['c'].value)"}}}
}POST task1/_search?size=0
{"aggs": {"range_a": {"range": {"field": "a","ranges": [{"to":-2},{"from": -5,"to": 5},{"from": 5}]}}}
}
  1. analyzer+reindex。在集群一上有task2索引,请重建它到task2_new索引上,并满足以下要求:
    ● 集群一的title字段包含有关键字’yoo-hoo’和’yoohoo’,不管搜索’yoohoo’还是’yoo-hoo’,它们的结果应该一样
    ● task2_new和task2的mapping应该一样
PUT task2
{"settings": {"number_of_replicas": 0,"number_of_shards": 1},"mappings": {"properties": {"title":{"type": "text"}}}
}
POST task2/_doc/1
{"title":"Yoo-Hoo"}
POST task2/_doc/2
{"title":"YooHoo"}
PUT task2_new
{"settings": {"analysis": {"analyzer": {"my_analyzer":{"char_filter":["my_char_filter"],"tokenizer":"standard","filter":["lowercase"]}},"char_filter": {"my_char_filter":{"type":"mapping","mappings":["-=>"]}}}},"mappings": {"properties": {"title":{"type": "text","analyzer": "my_analyzer"}}}
}POST /_reindex
{"source": {"index": "task2"},"dest": {"index": "task2_new"}
}POST task2_new/_search
{"query": {"match": {"title": "yoohoo"}}
}
  1. 数据流+索引生命周期管理。

    ● 现有以下文档,请编写一个名为test_data_stream数据流满足以下请求:

    {"@timestamp": "2099-03-08T11:04:05.000Z","message": "test"
    }
    

    ● 数据流索引的主分片数为3,副本分片数为1
    ● 将上述文档填充到数据流中去

ILM配置,建议直接通过kibana 配置

PUT _ilm/policy/my_exam2_policy
{"policy": {"phases": {"hot": {"min_age": "1d","actions": {"set_priority": {"priority": 100},"rollover": {"max_age": "7d","max_docs": 1000,"max_size": "5gb"}}},"warm": {"min_age": "1d","actions": {"set_priority": {"priority": 50},"allocate": {"number_of_replicas": 1,"include": {"_name": "","_ip": ""},"exclude": {"_name": "","_ip": ""},"require": {"_name": "","_ip": "","my_node_type":"warm"}},"shrink": {"number_of_shards": 1},"forcemerge": {"max_num_segments": 1}}},"cold": {"min_age": "1d","actions": {"set_priority": {"priority": 0},"freeze": {},"allocate": {"number_of_replicas": 1,"include": {"_name": "","_ip": ""},"exclude": {"_name": "","_ip": ""},"require": {"_name": "","_ip": "","my_node_type":"cold"}}}}}}
}
PUT _component_template/my_component_template_exam2
{"template": {"settings": {"index.lifecycle.name":"my_exam2_policy","index.number_of_shards":3,"index.number_of_replicas":1},"mappings": {"properties": {"@timestamp":{"type": "date"},"message":{"type": "text"}}}}
}
//使用 composed_of,方便编写 mapping 的内容
PUT _index_template/my_index_template_exam2
{"index_patterns": ["test_data_stream*"],"data_stream": { },"composed_of": [ "my_component_template_exam2" ],"priority": 500
}//使用 op_type=create,向 datastream 写入数据
POST test_data_stream/_doc/1?op_type=create
{"@timestamp":"2099-03-08T11:04:05.000Z","message":"test"}
  1. CCR,把cluster1上的一个索引,复制到cluster2上

  2. 查询模板
    ● 对task5编写一个查询模板,并满足以下要求:
    ● 使用a_01参数查询’a’字段;
    ● 使用start_date和end_date参数范围查询timestamp字段
    ● 如果没有提供end_date字段,那么结束时间默认是现在
    ● 查询结果中b字段必须equals’b’,
    ● 查询2018年6月1日到现在的数据,a字段包含关键字’aaa’

DELETE task5
PUT task5
{"mappings": {"properties": {"a":{"type": "text"},"b":{"type": "keyword"},"timestamp":{"type": "date"}}}
}POST /task5/_doc/1
{"a":"aaa AAA", "b":"b", "timestamp":"2021-11-11T11:21:21.000Z"}
PUT _scripts/my-search-template
{"script": {"lang": "mustache","source": {"query": {"bool": {"must": [{"match": {"a": "aaa"}},{"term": {"b": "b"}}],"should": [{"match": {"a": "{{a_01}}"}},{"range": {"timestamp": {"gte": "{{start_date}}","lte": "{{end_date}}{{^end_date}}now{{/end_date}}"}}}]}}}}
}GET task5/_search/template
{"id": "my-search-template","params": {"a_01": "aaa","start_date": "2018-06-01"}
}
  1. earthquakes索引中包含了过去11个月的地震信息,请通过一句查询,获取以下信息
    ● 过去11个月,每个月的平均地震等级(magiitude)
    ● 过去11个月里,平均地震等级最高的一个月及其平均地震等级
    ● 搜索不能返回任何文档
DELETE earthquakesPUT earthquakes
{"settings":{"number_of_replicas":0,"number_of_shards":1},"mappings":{"properties": {"earth_date":{"type": "date"},"magiitude":{"type": "float"}}}
}POST earthquakes/_bulk
{"index":{"_id":1}}
{"earth_date":"2012-01-01","magiitude": 4.5}
{"index":{"_id":2}}
{"earth_date":"2012-02-01","magiitude": 5.5}
{"index":{"_id":3}}
{"earth_date":"2012-03-01","magiitude": 5.5}
{"index":{"_id":4}}
{"earth_date":"2012-04-01","magiitude": 6.5}
{"index":{"_id":5}}
{"earth_date":"2012-04-02","magiitude": 7.5}
{"index":{"_id":6}}
{"earth_date":"2012-05-01","magiitude": 4.5}
{"index":{"_id":7}}
{"earth_date":"2012-06-01","magiitude": 3.2}
{"index":{"_id":8}}
{"earth_date":"2012-07-01","magiitude": 4.2}
{"index":{"_id":9}}
{"earth_date":"2012-08-01","magiitude": 5.2}
{"index":{"_id":10}}
{"earth_date":"2012-09-01","magiitude": 5.5}
{"index":{"_id":11}}
{"earth_date":"2012-10-01","magiitude": 3.5}
{"index":{"_id":12}}
{"earth_date":"2012-10-02","magiitude": 4.5}
POST earthquakes/_search?size=0
{"aggs": {"bucket_month": {"date_histogram": {"field": "earth_date","calendar_interval": "month","format": "yyyy-MM-dd"},"aggs": {"avg_magiitude": {"avg": {"field": "magiitude"}}}},"avg_magiitude_all":{"avg": {"field": "magiitude"}},"max_avg_magiitude_by_month":{"max_bucket": {"buckets_path": "bucket_month>avg_magiitude"}}}
}
  1. 目前有个索引是task3,用oa、OA、Oa、oA phrase查询是3条,使用dingding的phrase查询是2条,通过reindex 索引后能够使得使用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"}
PUT task3_new
{"settings": {"number_of_replicas": 0,"analysis": {"analyzer": {"my_analyzer": {"tokenizer": "standard","filter": ["my_filter","lowercase"]}},"filter": {"my_filter": {"type": "synonym","synonyms": ["oa,OA,Oa,oA,0A,dingding"]}}}},"mappings": {"properties": {"title": {"type": "text","analyzer": "my_analyzer"}}}
}POST /_reindex
{"source": {"index": "task3"},"dest": {"index": "task3_new"}
}POST task3_new/_search
{"query": {"match": {"title": "oa"}}
}
  1. 索引 movie-1,保存的电影信息,title是题目,tags是电影的标签。

    ● 在title中包含“my”或者“me”。
    ● 如果在tags中包含"romatic movies",该条算分提高,如果不包含则算分不变
    知识点:自定义评分

PUT movie-1
{"mappings": {"properties": {"title":{"type": "text"},"tags":{"type": "keyword"}}}
}
POST movie-1/_doc/1
{"title":"my me", "tags":["romatic movies"]}
POST movie-1/_search
{"query": {"function_score": {"query": {"bool": {"should": [{"match": {"title": "my"}},{"match": {"title": "me"}}]}},"functions": [{"filter": {"term": {"tags": "romatic movies"}},"weight": 5}]}}
}
  1. 对集群一上的task9索引编写一个查询,并满足以下要求:
    ● ‘a’,‘b’,‘c’字段至少有两个字段匹配中’test’关键字
    ● 对查询结果进行排序,先按照’a’字段进行降序排序,再按照’_socre’进行升序排序
    ● 'a’字段的返回结果高亮显示,前标签是,后标签是
PUT task9
{"mappings": {"properties": {"a":{"type": "keyword"},"b":{"type": "text"},"c":{"type": "text"}}}
}
POST task9/_search
{"query": {"bool": {"should": [{"match": {"a": "test"}},{"match": {"b": "test"}},{"match": {"c": "test"}}],"minimum_should_match": 2}},"highlight": {"fields": {"a":{"pre_tags": [""],"post_tags": [""]}}},"sort": [{"a": {"order": "desc"}},{"_score":{"order": "asc"}}]
}

相关内容

热门资讯

常用商务英语口语   商务英语是以适应职场生活的语言要求为目的,内容涉及到商务活动的方方面面。下面是小编收集的常用商务...
六年级上册英语第一单元练习题   一、根据要求写单词。  1.dry(反义词)__________________  2.writ...
复活节英文怎么说 复活节英文怎么说?复活节的英语翻译是什么?复活节:Easter;"Easter,anniversar...
2008年北京奥运会主题曲 2008年北京奥运会(第29届夏季奥林匹克运动会),2008年8月8日到2008年8月24日在中华人...
英语道歉信 英语道歉信15篇  在日常生活中,道歉信的使用频率越来越高,通过道歉信,我们可以更好地解释事情发生的...
六年级英语专题训练(连词成句... 六年级英语专题训练(连词成句30题)  1. have,playhouse,many,I,toy,i...
上班迟到情况说明英语   每个人都或多或少的迟到过那么几次,因为各种原因,可能生病,可能因为交通堵车,可能是因为天气冷,有...
小学英语教学论文 小学英语教学论文范文  引导语:英语教育一直都是每个家长所器重的,那么有关小学英语教学论文要怎么写呢...
英语口语学习必看的方法技巧 英语口语学习必看的方法技巧如何才能说流利的英语? 说外语时,我们主要应做到四件事:理解、回答、提问、...
四级英语作文选:Birth ... 四级英语作文范文选:Birth controlSince the Chinese Governmen...
金融专业英语面试自我介绍 金融专业英语面试自我介绍3篇  金融专业的学生面试时,面试官要求用英语做自我介绍该怎么说。下面是小编...
我的李老师走了四年级英语日记... 我的李老师走了四年级英语日记带翻译  我上了五个学期的小学却换了六任老师,李老师是带我们班最长的语文...
小学三年级英语日记带翻译捡玉... 小学三年级英语日记带翻译捡玉米  今天,我和妈妈去外婆家,外婆家有刚剥的`玉米棒上带有玉米籽,好大的...
七年级英语优秀教学设计 七年级英语优秀教学设计  作为一位兢兢业业的人民教师,常常要写一份优秀的教学设计,教学设计是把教学原...
我的英语老师作文 我的英语老师作文(通用21篇)  在日常生活或是工作学习中,大家都有写作文的经历,对作文很是熟悉吧,...
英语老师教学经验总结 英语老师教学经验总结(通用19篇)  总结是指社会团体、企业单位和个人对某一阶段的学习、工作或其完成...
初一英语暑假作业答案 初一英语暑假作业答案  英语练习一(基础训练)第一题1.D2.H3.E4.F5.I6.A7.J8.C...
大学生的英语演讲稿 大学生的英语演讲稿范文(精选10篇)  使用正确的写作思路书写演讲稿会更加事半功倍。在现实社会中,越...
VOA美国之音英语学习网址 VOA美国之音英语学习推荐网址 美国之音网站已经成为语言学习最重要的资源站点,在互联网上还有若干网站...
商务英语期末试卷 Part I Term Translation (20%)Section A: Translate ...