介绍
介绍
福哥在通过Elasticsearch建立搜索引擎的时候发现了一个问题,同时设置文档标题和文档正文作为匹配字段的时候,如果标题或者正文没有匹配文档就无法被查询到
为了解决这个问题,福哥想出了一个简单的做法
教程
通过同时使用 must 和 should 关键字,加上不同的匹配精度,达到比较理想的查询结果的目的
示例
给出一个查询示例
{
"bool": {
"must": [
{"match": {"doctype": 123456}},
{
"bool": {
"should": [
{"match": {"title": {
"query": "福哥 andy",
"minimum_should_match": "60%"
}}},
{"match": {"content": {
"query": "福哥 andy",
"minimum_should_match": "80%"
}}}
]
}
}
]
}
}我们设置条件 doctype 为 123456,同时 title 匹配度达到 60% 或者 content 匹配度达到 80% 的文档会被查询出来