一:  一个请求到达es集群,选中一个coordinate节点以后,会通过请求路由到指定primary shard中,如果分发策略选择为round-robin,如果来4个请求,则2个打到primary shard中2个打到replic shard中。

二: es在多个shard进行分片但数据倾斜严重的时候有可能会发生搜索score不准的情况,因为IDF分值的计算方法实在shard本地完成的;如shard1中数据较多,在计算某一词搜索时的分值时会导致分值整体下降,而这时shard2中出现的词频较少会整体分值偏高,这样容易导致原本不太相关的内容却变得分值高了起来,从而使排序不准;解决方法就是让多个shard在生产环境中尽量做到数据均衡分布,这样就不会因为score的本地计算而整体受影响。

三: es计算分值时有两种策略:

1)most-field->默认策略是全文检索的所有关键词,在document的每一个field中可匹配的次数越多则分值越高;规则:(每个match中field匹配分值的和) *(实际document匹配到了字段个数)/(query中match的个数) ,如下代码:

  1. GET /index3/type3/_search
  2. {
  3. "query": {
  4. "bool": {
  5. "should": [
  6. {
  7. "match": {
  8. "title":"spark"//title中可匹配成功
  9. }
  10. },
  11. {
  12. "match": {
  13. "content":"java"//content中也可匹配成功
  14. }
  15. }
  16. ]
  17. }
  18. }
  19. }

2)beast-field->如果使用dis_max,document的分值则会根据match中field匹配分值最高的决定,也就是说和其他属性无关

  1. GET /index3/type3/_search
  2. {
  3. "query": {
  4. "dis_max": {
  5. "queries": [
  6. {
  7. "match": {
  8. "title": "spark"
  9. }
  10. },
  11. {
  12. "match": {
  13. "content": "java"
  14. }
  15. }
  16. ]
  17. }
  18. }

3)es中除了most_fields和beast_fields以外,使用cross_fields的情况还是比较多的,使用es系统中默认的cross_fields策略实质是将 "fields": ["name","content"]两个字段的内容放到一起后建立索引,这样就能通过一个fullField字段进行fullText,使结果更加准确

  1. 搜索参数:
  2. GET /index2/type2/_search
  3. {
  4. "query": {
  5. "multi_match": {
  6. "query": "happening like",
  7. //query中的搜索词条去content和name两个字段中来匹配,不过会由于两个字段mapping定义不同导致得分不同,排序结果可能有差异
  8. "fields": ["name","content"],
  9. //best_fields策略是每个document的得分等于得分最高的match field的值;而匹配出最佳以后,其它document得分未必准确;most_fields根据每个field的评分计算出ducoment的综合评分
  10. "type":"cross_fields",
  11. "operator":"and"
  12. }
  13. }
  14. }
  15. 结果:
  16. {
  17. "took": 36,
  18. "timed_out": false,
  19. "_shards": {
  20. "total": 5,
  21. "successful": 5,
  22. "failed": 0
  23. },
  24. "hits": {
  25. "total": 3,
  26. "max_score": 0.84968257,
  27. "hits": [
  28. {
  29. "_index": "index2",
  30. "_type": "type2",
  31. "_id": "2",
  32. "_score": 0.84968257,
  33. "_source": {
  34. "num": 10,
  35. "title": "他的名字",
  36. "name": "yes happening like write",
  37. "content": "happening like"
  38. }
  39. },
  40. {
  41. "_index": "index2",
  42. "_type": "type2",
  43. "_id": "4",
  44. "_score": 0.8164005,
  45. "_source": {
  46. "num": 1000,
  47. "title": "我的名字",
  48. "name": "happening like write",
  49. "content": "happening hello like yeas and he happening like had read a lot about happening hello like"
  50. }
  51. },
  52. {
  53. "_index": "index2",
  54. "_type": "type2",
  55. "_id": "3",
  56. "_score": 0.5063205,
  57. "_source": {
  58. "num": 105,
  59. "title": "这是谁的名字",
  60. "name": "happening like write",
  61. "content": " national treasure because of its rare number and cute appearance. Many foreign people are so crazy about pandas and they can’t watching these lovely creatures all the time. Though some action"
  62. }
  63. }
  64. ]
  65. }
  66. }

四:提升全文检索效果的两种方法

1) 使用boost提升检索分值

  1. GET index3/type3/_search
  2. {
  3. "query": {
  4. "bool": {
  5. "should": [
  6. {
  7. "match": {
  8. "content": {
  9. "query": "from",
  10. "boost":5//使用boost将term检索评分提升5倍
  11. }
  12. }
  13. },{
  14. "match": {
  15. "content": {
  16. "query": "foot"//如果不使用boost则搜索foot则会得分较高
  17. }
  18. }
  19. }
  20. ]
  21. }
  22. }
  23. }
  24. 结果:
  25. {
  26. "took": 3,
  27. "timed_out": false,
  28. "_shards": {
  29. "total": 5,
  30. "successful": 5,
  31. "failed": 0
  32. },
  33. "hits": {
  34. "total": 3,
  35. "max_score": 1.3150566,
  36. "hits": [
  37. {
  38. "_index": "index3",
  39. "_type": "type3",
  40. "_id": "1",
  41. "_score": 1.3150566,
  42. "_source": {
  43. "date": "2019-01-02",
  44. "name": "the little",
  45. "content": "Half the hello book ideas in his talk were plagiarized from an article I wrote last month.",
  46. "no": "123"
  47. }
  48. },
  49. {
  50. "_index": "index3",
  51. "_type": "type3",
  52. "_id": "5",
  53. "_score": 1.3114156,
  54. "_source": {
  55. "date": "2019-05-01",
  56. "name": "http litty",
  57. "content": "There are hello moments in life when you miss book someone so much that you just want to pick them from your dreams",
  58. "no": "564",
  59. "description": "描述"
  60. }
  61. },
  62. {
  63. "_index": "index3",
  64. "_type": "type3",
  65. "_id": "3",
  66. "_score": 0.28582606,
  67. "_source": {
  68. "date": "2019-07-01",
  69. "name": "very tag",
  70. "content": "Some of our hello comrades love book to write long articles with no substance, very much like the foot bindings of a slattern, long as well as smelly",
  71. "no": "123"
  72. }
  73. }
  74. ]
  75. }
  76. }

2)使用boosting的positive和negative进行反向筛选,通过设置 (negative_boost:0.5) 降低分值

  1. GET index3/type3/_search
  2. {
  3. "query": {
  4. "boosting": {
  5. //正常匹配的
  6. "positive": {
  7. "match": {
  8. "content": "from"
  9. }
  10. },
  11. //降低分值去匹配的,以下字段的分值乘以negative_boost值
  12. "negative": {
  13. "match": {
  14. "content": {
  15. "query": "Half"
  16. }
  17. }
  18. },
  19. "negative_boost": 0.1
  20. }
  21. }
  22. }
  23. 结果:
  24. {
  25. "took": 2,
  26. "timed_out": false,
  27. "_shards": {
  28. "total": 5,
  29. "successful": 5,
  30. "failed": 0
  31. },
  32. "hits": {
  33. "total": 2,
  34. "max_score": 0.26228312,
  35. "hits": [
  36. {
  37. "_index": "index3",
  38. "_type": "type3",
  39. "_id": "5",
  40. "_score": 0.26228312,
  41. "_source": {
  42. "date": "2019-05-01",
  43. "name": "http litty",
  44. "content": "There are hello moments in life when you miss book someone so much that you just want to pick them from your dreams",
  45. "no": "564",
  46. "description": "描述"
  47. }
  48. },
  49. {
  50. "_index": "index3",
  51. "_type": "type3",
  52. "_id": "1",
  53. "_score": 0.026301134,
  54. "_source": {
  55. "date": "2019-01-02",
  56. "name": "the little",
  57. "content": "Half the hello book ideas in his talk were plagiarized from an article I wrote last month.",
  58. "no": "123"
  59. }
  60. }
  61. ]
  62. }
  63. }

es原理的更多相关文章

  1. ES原理(转载)

    该博客属于转载,是很经典的一篇关于ES的介绍: Elasticsearch 是一个兼有搜索引擎和NoSQL数据库功能的开源系统,基于Java/Lucene构建,可以用于全文搜索,结构化搜索以及近实时分 ...

  2. 【漫画】ES原理 必知必会的倒排索引和分词

    倒排索引的初衷 倒排索引,它也是索引.索引,初衷都是为了快速检索到你要的数据. 我相信你一定知道mysql的索引,如果对某一个字段加了索引,一般来说查询该字段速度是可以有显著的提升. 每种数据库都有自 ...

  3. 【Elasticsearch 技术分享】—— 十张图带大家看懂 ES 原理 !明白为什么说:ES 是准实时的!

    前言 说到 Elasticsearch ,其中最明显的一个特点就是 near real-time 准实时 -- 当文档存储在Elasticsearch中时,将在1秒内以几乎实时的方式对其进行索引和完全 ...

  4. 全文检索原理以及es

    最近要做个文章搜索,对全文检索原理以及es原理进行了一些调研, 1.  es索引文件为多个文本文件描述,索引文件中的内容构成可见 http://elasticsearch.cn/article/86 ...

  5. es集群数据库~原理细节

    ES原理一 基本定义  index(索引)  相当于mysql中的数据库  type(类型)  相当于mysql中的一张表  document(文档)  相当于mysql中的一行(一条记录)  fie ...

  6. Elasticsearch(二)--集群原理及优化

    一.ES原理 1.索引结构ES是面向文档的 各种文本内容以文档的形式存储到ES中,文档可以是一封邮件.一条日志,或者一个网页的内容.一般使用 JSON 作为文档的序列化格式,文档可以有很多字段,在创建 ...

  7. 《ElasticSearch6.x实战教程》之父-子关系文档

    第七章-父-子关系文档 打虎亲兄弟,上阵父子兵. 本章作为复杂搜索的铺垫,介绍父子文档是为了更好的介绍复杂场景下的ES操作. 在非关系型数据库数据库中,我们常常会有表与表的关联查询.例如学生表和成绩表 ...

  8. python操作elasticsearch增、删、改、查

    最近接触了个新东西--es数据库 这东西虽然被用的很多,但我是前些天刚刚接触的,发现其资料不多,学起来极其痛苦,写个文章记录下 导入库from elasticsearch import Elastic ...

  9. ELK集群之elasticsearch(3)

    Elasticsearch-基础介绍及索引原理分析 介绍 Elasticsearch 是一个分布式可扩展的实时搜索和分析引擎,一个建立在全文搜索引擎 Apache Lucene(TM) 基础上的搜索引 ...

随机推荐

  1. 《挑战30天C++入门极限》新手入门:C/C++中的结构体

        新手入门:C/C++中的结构体 什么是结构体? 简单的来说,结构体就是一个可以包含不同数据类型的一个结构,它是一种可以自己定义的数据类型,它的特点和数组主要有两点不同,首先结构体可以在一个结构 ...

  2. OpenFOAM清理计算结果(只保留原始的0,system,constant)

    原视频下载地址:https://yunpan.cn/cMpyLZq8sWQgq(提取码:a08b)

  3. 3、vueJs基础知识03

    vue过渡(动画) 本质走的css3: transtion ,animation <div id="div1" v-show="bSign" transi ...

  4. mac安装gmpy2

    brew install libmpc brew install mpfr pip install gmpy2

  5. OpenMP基本概念【转】

    OpenMP是一种用于共享内存并行系统的多线程程序设计方案,支持的编程语言包括C.C++和Fortran.OpenMP提供了对并行算法的高层抽象描述,特别适合在多核CPU机器上的并行程序设计.编译器根 ...

  6. Visual Studio、.NET Framework、VC++、C#各个版本的对应关系

    Visual Studio..NET Framework.VC++.C#各个版本的对应关系 Visual Studio版本 .NET Framework版本 内部版本 VC++版本 C#版本 Visu ...

  7. Django微信小程序后台开发教程

    本文链接:https://blog.csdn.net/qq_43467898/article/details/83187698Django微信小程序后台开发教程1 申请小程序,创建hello worl ...

  8. 从内核3.7版本开始,Linux就开始支持VXLAN 到了内核3.12版本,Linux对VXLAN的支持已经完备,支持单播和组播,IPv4和IPv6。

    一.关于VXLAN VXLAN 是 Virtual eXtensible LANs 的缩写,它是对 VLAN 的一个扩展,是非常新的一个 tunnel 技术,在Open vSwitch中应用也非常多. ...

  9. Gradle vs. Maven: Performance, Compatibility, Speed, & Builds

    Gradle vs. Maven: Performance, Compatibility, Speed, & Buildshttps://stackify.com/gradle-vs-mave ...

  10. [转]linux 下 使用 c / c++ 调用curl库 做通信开发

    example:   1. http://curl.haxx.se/libcurl/c/example.html  2. http://www.libcurl.org/book:  1. http:/ ...