主要知识点

  • most-fields策略的用法
  • most-fields策略和best-fields的比较

 
 

 
 

best-fields策略:将某一个field匹配尽可能多的关键词的doc优先返回回来,也就是说如果这个filed匹配了更多的关键词,那么这个doc的分数就会更高。

most-fields策略:尽可能返回更多field匹配到某个关键词的doc,优先返回回来。也就是说,如果一个doc中有更多的field匹配到了关键词,那么这个doc的得分会更高。

 
 

一、准备数据

1、建立一个自定义mapping的index

POST /forum/_mapping/article

{

"properties": {

"sub_title": {

"type": "string",

"analyzer": "english",

"fields": {

"std": {

"type": "string",

"analyzer": "standard"

}

}

}

}

}

 
 

2、插入数据

POST /forum/article/_bulk

{ "update": { "_id": "1"} }

{ "doc" : {"sub_title" : "learning more courses"} }

{ "update": { "_id": "2"} }

{ "doc" : {"sub_title" : "learned a lot of course"} }

{ "update": { "_id": "3"} }

{ "doc" : {"sub_title" : "we have a lot of fun"} }

{ "update": { "_id": "4"} }

{ "doc" : {"sub_title" : "both of them are good"} }

{ "update": { "_id": "5"} }

{ "doc" : {"sub_title" : "haha, hello world"} }

 
 

3、进行match搜索

GET /forum/article/_search

{

"query": {

"match": {

"sub_title": "learning courses"

}

}

}

执行结果是:

{

"took": 3,

"timed_out": false,

"_shards": {

"total": 5,

"successful": 5,

"failed": 0

},

"hits": {

"total": 2,

"max_score": 1.219939,

"hits": [

{

"_index": "forum",

"_type": "article",

"_id": "2",

"_score": 1.219939,

"_source": {

"articleID": "KDKE-B-9947-#kL5",

"userID": 1,

"hidden": false,

"postDate": "2017-01-02",

"tag": [

"java"

],

"tag_cnt": 1,

"view_cnt": 50,

"title": "this is java blog",

"content": "i think java is the best programming language",

"sub_title": "learned a lot of course"

}

},

{

"_index": "forum",

"_type": "article",

"_id": "1",

"_score": 0.5063205,

"_source": {

"articleID": "XHDK-A-1293-#fJ3",

"userID": 1,

"hidden": false,

"postDate": "2017-01-01",

"tag": [

"java",

"hadoop"

],

"tag_cnt": 2,

"view_cnt": 30,

"title": "this is java and elasticsearch blog",

"content": "i like to write best elasticsearch article",

"sub_title": "learning more courses"

}

}

]

}

}

 
 

如果我们用的是类似于english analyzer这种分词器的话,就会将单词还原为其最基本的形态,这个还原单词的过程叫做stemmer。这样可能{ "doc" : {"sub_title" : "learned a lot of course"} },就排在了{ "doc" : {"sub_title" : "learning more courses"} }的前面

learning --> learn

learned --> learn

courses --> course

sub_titile: learning coureses --> learn course

4、加上standerd分词器,

standerd不会去还原单词的基本形态,会保留单词的原样。

POST /forum/_mapping/article

{

"properties": {

"sub_title": {

"type": "string",

"analyzer": "english",

"fields": {

"std": {

"type": "string",

"analyzer": "standard"

}

}

}

}

}

 
 

 
 

、进行multi_match进行搜索。

GET /forum/article/_search

{

"query": {

"multi_match": {

"query": "learning courses",

"type": "most_fields",

"fields": [ "sub_title", "sub_title.std" ]

}

}

}

执行结果是:

{

"took": 2,

"timed_out": false,

"_shards": {

"total": 5,

"successful": 5,

"failed": 0

},

"hits": {

"total": 2,

"max_score": 1.219939,

"hits": [

{

"_index": "forum",

"_type": "article",

"_id": "2",

"_score": 1.219939,

"_source": {

"articleID": "KDKE-B-9947-#kL5",

"userID": 1,

"hidden": false,

"postDate": "2017-01-02",

"tag": [

"java"

],

"tag_cnt": 1,

"view_cnt": 50,

"title": "this is java blog",

"content": "i think java is the best programming language",

"sub_title": "learned a lot of course"

}

},

{

"_index": "forum",

"_type": "article",

"_id": "1",

"_score": 1.012641,

"_source": {

"articleID": "XHDK-A-1293-#fJ3",

"userID": 1,

"hidden": false,

"postDate": "2017-01-01",

"tag": [

"java",

"hadoop"

],

"tag_cnt": 2,

"view_cnt": 30,

"title": "this is java and elasticsearch blog",

"content": "i like to write best elasticsearch article",

"sub_title": "learning more courses"

}

}

]

}

}

 
 

你问我,具体的分数怎么算出来的,很难说,因为这个东西很复杂,
还不只是TF/IDF算法。因为不同的query,不同的语法,都有不同的计算score的细节。

 
 

与best_fields的区别

 
 

(1)best_fields,是对多个field进行搜索,挑选某个field匹配度最高的那个分数,同时在多个query最高分相同的情况下,在一定程度上考虑其他query的分数。简单来说,你对多个field进行搜索,就想搜索到某一个field尽可能包含更多关键字的数据

 
 

优点:通过best_fields策略,以及综合考虑其他field,还有minimum_should_match支持,可以尽可能精准地将匹配的结果推送到最前面

缺点:除了那些精准匹配的结果,其他差不多大的结果,排序结果不是太均匀,没有什么区分度了

 
 

实际的例子:百度之类的搜索引擎,最匹配的到最前面,但是其他的就没什么区分度了

 
 

(2)most_fields,综合多个field一起进行搜索,尽可能多地让所有field的query参与到总分数的计算中来,此时就会是个大杂烩,出现类似best_fields案例最开始的那个结果,结果不一定精准,某一个document的一个field包含更多的关键字,但是因为其他document有更多field匹配到了,所以排在了前面;所以需要建立类似sub_title.std这样的field,尽可能让某一个field精准匹配query string,贡献更高的分数,将更精准匹配的数据排到前面

 
 

优点:将尽可能匹配更多field的结果推送到最前面,整个排序结果是比较均匀的

缺点:可能那些精准匹配的结果,无法推送到最前面

 
 

实际的例子:wiki,明显的most_fields策略,搜索结果比较均匀,但是的确要翻好几页才能找到最匹配的结果

14.multi_match+most-fields策略的更多相关文章

  1. Elasticsearch学习之深入搜索三 --- best fields策略

    1. 为帖子数据增加content字段 POST /forum/article/_bulk { "} } { "doc" : {"content" : ...

  2. 11.best fields策略(dis_max参数设置)

    主要知识点 常规multi-field搜索结果分析 dis_max参数设置     一.为帖子数据增加content字段     POST /forum/article/_bulk { "u ...

  3. 面试系列14 redis的过期策略都有哪些

    (1)设置过期时间 我们set key的时候,都可以给一个expire time,就是过期时间,指定这个key比如说只能存活1个小时?10分钟?这个很有用,我们自己可以指定缓存到期就失效. 如果假设你 ...

  4. 阿里云API网关(14)流控策略

    网关指南: https://help.aliyun.com/document_detail/29487.html?spm=5176.doc48835.6.550.23Oqbl 网关控制台: https ...

  5. Android内存管理(4)*官方教程 含「高效内存的16条策略」 Managing Your App's Memory

    Managing Your App's Memory In this document How Android Manages Memory Sharing Memory Allocating and ...

  6. ElasticSearch query_string vs multi_match cross_fields query

    ElasticSearch query_string vs multi_match cross_fields query 本文记录以字段为中心的查询和以词为中心的查询这两种查询方式的区别以及在Elas ...

  7. Elasticsearch.Net 异常:[match] query doesn't support multiple fields, found [field] and [query]

    用Elasticsearch.Net检索数据,报异常: )); ElasticLowLevelClient client = new ElasticLowLevelClient(settings); ...

  8. WeQuant交易策略—EMV

    EMV指标策略 简介 EMV(Ease of Movement Value, 简易波动指标),它是由RichardW.ArmJr.根据等量图和压缩图的原理设计而成, 目的是将价格与成交量的变化结合成一 ...

  9. ES进阶--02

    第11节深度探秘搜索技术_案例实战基于dis_max实现best fields策略进行多字段搜索 课程大纲 1.为帖子数据增加content字段 POST /forum/article/_bulk{ ...

随机推荐

  1. 关于ZEDboard

    核心芯片:核心ZYNQ XC7Z020CLG484 双核Cortex-A9 MPcore.主频达到667MHz,板载512MB内存 12V@3A的电源适配器 使用的SD卡中预装了Linaro系统,这是 ...

  2. 数据挖掘算法学习(八)Adaboost算法

    本文不定期更新.原创文章,转载请附上链接http://blog.csdn.net/iemyxie/article/details/40423907 谢谢 Adaboost是一种迭代算法,其核心思想是针 ...

  3. had been doing 和had been done有什么差别

    had been doing 和had been done有什么差别 浏览 37114 次 1个回答 最佳答案 21Doreen 来自科学教育类芝麻团 推荐于2017-10-15   1.首先要区分h ...

  4. 不仅开源,而且对企业应用完全免费!ExtAspNet弃用GPL v2,拥抱Apache License 2.0(转)

    不仅开源,而且对企业应用完全免费!ExtAspNet弃用GPL v2,拥抱Apache License 2.0(转) 提出问题 ExtAspNet开源以来,一直坚持开源免费的原则,但是其GPL v2的 ...

  5. luogu 3834 【模板】可持久化线段树 1(主席树)

    我这种菜鸡还是%一下棒神比较好 #include<iostream> #include<cstdio> #include<cmath> #include<cs ...

  6. Ruby 遍历多个数组

    puts("----------------------------------------") puts("             多重指定 test") ...

  7. IE下元素设置百分比的问题

    场景:近两天在做一个控件,该控件是一个tab型的,并且该tab有可能是两个tab标签,也有可能是多个tab标签,为了能够适应这种动态需求, 在设置标签宽度的时候,直接用的最外层容器除以tab的个数,然 ...

  8. 观察者模式-C#实现

    定义对象间的一种一对多的依赖关系,当一个对象的状态发生改变时,所有依赖于它的对象都得到通知并被自动更新. 观察者模式有四个角色:抽象主题.具体主题.抽象观察者.具体观察者. 抽象主题:把所有观察者对象 ...

  9. Codeforces 19E 树上差分

    思路: 先随便建出来一棵搜索树(图可能不连通?) 每一条非树边(剩下的边)和树边都可以构成一个环. 我们只看一个非树边和某些树边构成的这些环. 分成三种情况: 1.没有奇环  所有边都可以删 2.有一 ...

  10. Codeforces 903G 巧妙的线段树

    思路: 巧妙的线段树 想方法将网络流往数据结构方向转化 http://www.cnblogs.com/yyf0309/p/8724558.html //By SiriusRen #include &l ...