es原理
一: 一个请求到达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的个数) ,如下代码:
GET /index3/type3/_search
{
"query": {
"bool": {
"should": [
{
"match": {
"title":"spark"//title中可匹配成功
}
},
{
"match": {
"content":"java"//content中也可匹配成功
}
}
]
}
}
}
2)beast-field->如果使用dis_max,document的分值则会根据match中field匹配分值最高的决定,也就是说和其他属性无关
GET /index3/type3/_search
{
"query": {
"dis_max": {
"queries": [
{
"match": {
"title": "spark"
}
},
{
"match": {
"content": "java"
}
}
]
}
}
3)es中除了most_fields和beast_fields以外,使用cross_fields的情况还是比较多的,使用es系统中默认的cross_fields策略实质是将 "fields": ["name","content"]两个字段的内容放到一起后建立索引,这样就能通过一个fullField字段进行fullText,使结果更加准确
搜索参数:
GET /index2/type2/_search
{
"query": {
"multi_match": {
"query": "happening like",
//query中的搜索词条去content和name两个字段中来匹配,不过会由于两个字段mapping定义不同导致得分不同,排序结果可能有差异
"fields": ["name","content"],
//best_fields策略是每个document的得分等于得分最高的match field的值;而匹配出最佳以后,其它document得分未必准确;most_fields根据每个field的评分计算出ducoment的综合评分
"type":"cross_fields",
"operator":"and"
}
}
}
结果:
{
"took": 36,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 3,
"max_score": 0.84968257,
"hits": [
{
"_index": "index2",
"_type": "type2",
"_id": "2",
"_score": 0.84968257,
"_source": {
"num": 10,
"title": "他的名字",
"name": "yes happening like write",
"content": "happening like"
}
},
{
"_index": "index2",
"_type": "type2",
"_id": "4",
"_score": 0.8164005,
"_source": {
"num": 1000,
"title": "我的名字",
"name": "happening like write",
"content": "happening hello like yeas and he happening like had read a lot about happening hello like"
}
},
{
"_index": "index2",
"_type": "type2",
"_id": "3",
"_score": 0.5063205,
"_source": {
"num": 105,
"title": "这是谁的名字",
"name": "happening like write",
"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"
}
}
]
}
}
四:提升全文检索效果的两种方法
1) 使用boost提升检索分值
GET index3/type3/_search
{
"query": {
"bool": {
"should": [
{
"match": {
"content": {
"query": "from",
"boost":5//使用boost将term检索评分提升5倍
}
}
},{
"match": {
"content": {
"query": "foot"//如果不使用boost则搜索foot则会得分较高
}
}
}
]
}
}
}
结果:
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 3,
"max_score": 1.3150566,
"hits": [
{
"_index": "index3",
"_type": "type3",
"_id": "1",
"_score": 1.3150566,
"_source": {
"date": "2019-01-02",
"name": "the little",
"content": "Half the hello book ideas in his talk were plagiarized from an article I wrote last month.",
"no": "123"
}
},
{
"_index": "index3",
"_type": "type3",
"_id": "5",
"_score": 1.3114156,
"_source": {
"date": "2019-05-01",
"name": "http litty",
"content": "There are hello moments in life when you miss book someone so much that you just want to pick them from your dreams",
"no": "564",
"description": "描述"
}
},
{
"_index": "index3",
"_type": "type3",
"_id": "3",
"_score": 0.28582606,
"_source": {
"date": "2019-07-01",
"name": "very tag",
"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",
"no": "123"
}
}
]
}
}
2)使用boosting的positive和negative进行反向筛选,通过设置 (negative_boost:0.5) 降低分值
GET index3/type3/_search
{
"query": {
"boosting": {
//正常匹配的
"positive": {
"match": {
"content": "from"
}
},
//降低分值去匹配的,以下字段的分值乘以negative_boost值
"negative": {
"match": {
"content": {
"query": "Half"
}
}
},
"negative_boost": 0.1
}
}
}
结果:
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 0.26228312,
"hits": [
{
"_index": "index3",
"_type": "type3",
"_id": "5",
"_score": 0.26228312,
"_source": {
"date": "2019-05-01",
"name": "http litty",
"content": "There are hello moments in life when you miss book someone so much that you just want to pick them from your dreams",
"no": "564",
"description": "描述"
}
},
{
"_index": "index3",
"_type": "type3",
"_id": "1",
"_score": 0.026301134,
"_source": {
"date": "2019-01-02",
"name": "the little",
"content": "Half the hello book ideas in his talk were plagiarized from an article I wrote last month.",
"no": "123"
}
}
]
}
}
es原理的更多相关文章
- ES原理(转载)
该博客属于转载,是很经典的一篇关于ES的介绍: Elasticsearch 是一个兼有搜索引擎和NoSQL数据库功能的开源系统,基于Java/Lucene构建,可以用于全文搜索,结构化搜索以及近实时分 ...
- 【漫画】ES原理 必知必会的倒排索引和分词
倒排索引的初衷 倒排索引,它也是索引.索引,初衷都是为了快速检索到你要的数据. 我相信你一定知道mysql的索引,如果对某一个字段加了索引,一般来说查询该字段速度是可以有显著的提升. 每种数据库都有自 ...
- 【Elasticsearch 技术分享】—— 十张图带大家看懂 ES 原理 !明白为什么说:ES 是准实时的!
前言 说到 Elasticsearch ,其中最明显的一个特点就是 near real-time 准实时 -- 当文档存储在Elasticsearch中时,将在1秒内以几乎实时的方式对其进行索引和完全 ...
- 全文检索原理以及es
最近要做个文章搜索,对全文检索原理以及es原理进行了一些调研, 1. es索引文件为多个文本文件描述,索引文件中的内容构成可见 http://elasticsearch.cn/article/86 ...
- es集群数据库~原理细节
ES原理一 基本定义 index(索引) 相当于mysql中的数据库 type(类型) 相当于mysql中的一张表 document(文档) 相当于mysql中的一行(一条记录) fie ...
- Elasticsearch(二)--集群原理及优化
一.ES原理 1.索引结构ES是面向文档的 各种文本内容以文档的形式存储到ES中,文档可以是一封邮件.一条日志,或者一个网页的内容.一般使用 JSON 作为文档的序列化格式,文档可以有很多字段,在创建 ...
- 《ElasticSearch6.x实战教程》之父-子关系文档
第七章-父-子关系文档 打虎亲兄弟,上阵父子兵. 本章作为复杂搜索的铺垫,介绍父子文档是为了更好的介绍复杂场景下的ES操作. 在非关系型数据库数据库中,我们常常会有表与表的关联查询.例如学生表和成绩表 ...
- python操作elasticsearch增、删、改、查
最近接触了个新东西--es数据库 这东西虽然被用的很多,但我是前些天刚刚接触的,发现其资料不多,学起来极其痛苦,写个文章记录下 导入库from elasticsearch import Elastic ...
- ELK集群之elasticsearch(3)
Elasticsearch-基础介绍及索引原理分析 介绍 Elasticsearch 是一个分布式可扩展的实时搜索和分析引擎,一个建立在全文搜索引擎 Apache Lucene(TM) 基础上的搜索引 ...
随机推荐
- 深度Linux /etc/profile 环境变量生效问题
/etc/profile 环境变量生效问题 设置了环境变量后 ,使用source /etc/profile生效后,每次关闭终端后,都需要重新输入source /etc/profile命令使环境变量生效 ...
- RNN梯度消失和爆炸的原因 以及 LSTM如何解决梯度消失问题
RNN梯度消失和爆炸的原因 经典的RNN结构如下图所示: 假设我们的时间序列只有三段, 为给定值,神经元没有激活函数,则RNN最简单的前向传播过程如下: 假设在t=3时刻,损失函数为 . 则对于一 ...
- 【洛谷】P3177 [HAOI2015]树上染色
懒得复制题面了直接传送门吧 分析 直接求点与点之间的距离感觉不是很好求,所以我们考虑换一个求法. 瞄了一眼题解 距离跟路径上边的长度有关,所以我们直接来看每一条边的贡献吧(这谁想得到啊) 对于每一条边 ...
- Bootstrap selectpicker 下拉框多选获取选中value和多选获取文本值
1.页面代码: 页面引入: bootstrap-select.min.css和 bootstrap-select.min.js. defaults-zh_CN.min.js文件,并初始化下拉选项框. ...
- SignalR要求_转自:https://www.cnblogs.com/humble/p/3855137.html
SignalR 服务端组件可以被部署在诸多的服务器配置中,本节描述了它所支持的操作系统版本,.NET framework,IIS.以及其他组件 二.支持的服务器操作系统 SignalR服务端组件可以被 ...
- [转]IDE 、SATA、SCSI 的区别
IDE IDE的英文全称为“Integrated Drive Electronics”,即“电子集成驱动器”,它的 本意是指把“硬盘控制器”与“盘体”集成在一起的硬盘驱动器 .把盘体与控制器集成在 一 ...
- 阿里druid连接池监控数据自定义存储
如何将druid连接池监控到的sql执行效率,连接池资源情况等进行持久化存储,方便系统运维分析优化,以下案例初步测试成功. 第一部: 新建MyDruidStatLogger类实现接口 extends ...
- C#随机挑选某一个用户或者几个用户信息
&& u.EnabledMark == ).OrderBy(_=>Guid.NewGuid()).Take(); && u.EnabledMark == ).Or ...
- python 设计模式之桥接模式 Bridge Pattern
#写在前面 前面写了那么设计模式了,有没有觉得有些模式之间很类似,甚至感觉作用重叠了,模式并不是完全隔离和独立的,有的模式内部其实用到了其他模式的技术,但是又有自己的创新点,如果一味地认为每个模式都是 ...
- 小D课堂 - 零基础入门SpringBoot2.X到实战_第6节 SpringBoot拦截器实战和 Servlet3.0自定义Filter、Listener_24、深入SpringBoot过滤器和Servlet配置过滤器
笔记 1.深入SpringBoot2.x过滤器Filter和使用Servlet3.0配置自定义Filter实战(核心知识) 简介:讲解SpringBoot里面Filter讲解和使用Servle ...