一、题目
写一个查询,要求查询 kibana_sample_data_ecommerce 索引,且 day_of_week
、customer_gender
、currency
、type
这 4 个字段中至少两个以上。
1.1 考点
- Boolean
1.2 答案
GET kibana_sample_data_ecommerce/_search
{"query": {"bool": {"should": [{"term": {"day_of_week": {"value": "Monday"}}},{"term": {"customer_gender": {"value": "MALE"}}},{"term": {"currency": {"value": "EUR"}}},{"term": {"type": {"value": "order"}}}],"minimum_should_match": 2}}
}
二、题目
对 task 索引中文档的 fielda
, fieldb
, fieldc
字段进行查询,并
要求最终的算分是fielda
, fieldb
, fieldc
字段上算分的总和,同时要求对 fieldb
字段设置 boosting
值
# 创建符合条件的 task 索引,设置 field 字段,并写入数据
PUT task
{"mappings": {"properties": {"fielda":{"type": "text"},"fieldb":{"type": "text"},"fieldc":{"type": "text"},"fieldd":{"type": "long"}}}
}# 写入数据
POST task/_bulk
{"index":{}}
{"fielda":"中国人民广场", "fieldb":"天安门", "fieldc":"中国人民广场", "fieldd": 5}
{"index":{}}
{"fielda":"中华人民共和国万岁", "fieldb":"日月潭", "fieldc":"中国人民广场", "fieldd": 6}
{"index":{}}
{"fielda":"山上山下红旗飘飘", "fieldb":"农民翻身把歌唱", "fieldc":"中国人民广场", "fieldd": 4}
{"index":{}}
{"fielda":"中国共产党万岁", "fieldb":"中国人民广场", "fieldc":"中国人民广场", "fieldd": 5}
{"index":{}}
{"fielda":"春眠不觉晓", "fieldb":"中国人民", "fieldc":"处处闻啼鸟", "fieldd": 5}
2.1 考点
- Multi-match
2.2 答案
GET task/_search
{"query": {"multi_match" : {"query" : "中华人民","fields" : [ "fielda", "fieldb^2", "fieldc"] }}
}
这里更新一个 分数的计算方式
GET task/_search
{"query": {"multi_match" : {"query" : "中华人民","fields" : [ "fielda", "fieldb^2", "fieldc"],"type": "most_fields"}}
}