赞
踩
本文基于Elasticsearch7.x
全文搜索在搜索时, 会对输入的搜索文本进行分词, 然后去倒排索引中进行匹配, 只要能匹配上任意一个关键词(词项), 就可以作为结果返回.
在学习本篇博客前先了解下Elasticsearch全文搜索之基础语法API
添加搜索实例数据
POST /blogs/_bulk
{"index": {}}
{"post_date": "2020-01-01", "title": "Quick brown rabbits", "content": "Brown rabbits are commonly seen.", "author_id": 11401}
{"index": {}}
{"post_date": "2020-01-02", "title": "Keeping pets healthy", "content": "My quick brown fox eats rabbits on a regular basis.", "author_id": 11402}
{"index": {}}
{"post_date": "2020-01-03", "title": "My dog barks", "content": "I see a lot of barking dogs on the road.", "author_id": 11403}
bool
基础匹配API的实例都是对一个搜索文本进行匹配, 即单条件搜索. 下面我们来学习下bool多条件搜索, 即由多个搜索文本构成的复合搜索.
(1) bool语法
must, must_not, should这三个条件是会用于相关度分数计算的, 而filter不会, 从而filter的性能会更好. 由以上四种搜索子句合并为一条复合搜索语句, 这就是bool搜索.
基础匹配API中讲述的match, match_phrase, dis_max, multi_match, term是基础的搜索语法, bool搜索是基于它们来实现的.
(2) 实例
a. 基础使用
GET /blogs/_search { "query": { "bool": { "must": [ { "term": { "author_id": { "value": "11403" } } } ], "must_not": [ { "range": { "post_date": { "lte": "2020-01-02" } } } ], "should": [ { "term": { "title.keyword": { "value": "My dog barks" } } }, { "term": { "content
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。