一、题目
集群中有索引 task3
,用 oa、OA、Oa、oA 查询结构是 4 条,使用 dingding 的查询结果是 1 条。通过 reindex
索引 task3
为 task3_new
,能够使 task3_new
满足以下查询条件。
- 使用 oa、OA、Oa、oA、0A、dingding 查询都能够返回 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 答案
# 创建索引结构,定义分词器
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
编写一个查询,并满足以下要求:
a
,b
,c
字段至少有两个字段匹配中 test 关键字- 对查询结果进行排序,先按照
a
字段进行降序排序,再按照_socre
进行升序排序 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 考点
- Boolean
- Sort
- 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>"]}}}
}