当前位置: 首页 > news >正文

09-结构化搜索、搜索的相关性算分

  • term 查询执行精确值匹配,要求文档中的字段值与指定的词项完全相等。对于日期字段等精确值字段,通常使用 term 查询可以快速有效地匹配文档。
  • match 查询执行全文搜索,会对输入的文本进行分析,生成查询词项,并试图找到与这些词项匹配的文档
  • constant_score查询是一种特殊的查询,它会为每个匹配的文档分配一个固定的分数(默认为 1.0)

DELETE productsPOST /products/_bulk
{ "index": { "_id": 1 }}
{ "price" : 10,"avaliable":true,"date":"2023-01-01", "productID" : "XHDK-A-1293-#fJ3" }
{ "index": { "_id": 2 }}
{ "price" : 20,"avaliable":true,"date":"2023-01-01", "productID" : "KDKE-B-9947-#kL5" }
{ "index": { "_id": 3 }}
{ "price" : 30,"avaliable":true, "productID" : "JODL-X-1937-#pV7" }
{ "index": { "_id": 4 }}
{ "price" : 30,"avaliable":false, "productID" : "QQPX-R-3956-#aD8" }GET products/_mapping# 对布尔值 match 查询,有算分
POST products/_search
{"profile": "true","explain": true,"query": {"term": {"avaliable": true}}
}# 对布尔值,通过constant score 转成 filtering,没有算分
POST products/_search
{"profile": "true","explain": true,"query": {"constant_score": {"filter": {"term": {"avaliable": true}}}}
}# 数字类型 Term
POST products/_search
{"profile": "true","explain": true,"query": {"term": {"price": 30}}
}# 数字类型 terms
POST products/_search
{"query": {"constant_score": {"filter": {"terms": {"price": ["20","30"]}}}}
}# 数字 Range 查询
GET products/_search
{"query" : {"constant_score" : {"filter" : {"range" : {"price" : {"gte" : 20,"lte"  : 30}}}}}
}# 日期 range
POST products/_search
{"query" : {"constant_score" : {"filter" : {"range" : {"date" : {"gte" : "now-1y"}}}}}
}# exists查询
POST products/_search
{"query": {"constant_score": {"filter": {"exists": {"field": "date"}}}}
}# 处理多值字段
POST /movies/_bulk
{ "index": { "_id": 1 }}
{ "title" : "Father of the Bridge Part II","year":1995, "genre":"Comedy"}
{ "index": { "_id": 2 }}
{ "title" : "Dave","year":1993,"genre":["Comedy","Romance"] }# 处理多值字段,term 查询是包含,而不是等于
POST movies/_search
{"query": {"constant_score": {"filter": {"term": {"genre.keyword": "Comedy"}}}}
}# 字符类型 terms
POST products/_search
{"query": {"constant_score": {"filter": {"terms": {"productID.keyword": ["QQPX-R-3956-#aD8","JODL-X-1937-#pV7"]}}}}
}POST products/_search
{"profile": "true","explain": true,"query": {"match": {"price": 30}}
}POST products/_search
{"profile": "true","explain": true,"query": {"term": {"date": "2019-01-01"}}
}POST products/_search
{"profile": "true","explain": true,"query": {"match": {"date": "2019-01-01"}}
}POST products/_search
{"profile": "true","explain": true,"query": {"constant_score": {"filter": {"term": {"productID.keyword": "XHDK-A-1293-#fJ3"}}}}
}POST products/_search
{"profile": "true","explain": true,"query": {"term": {"productID.keyword": "XHDK-A-1293-#fJ3"}}
}# 对布尔数值
POST products/_search
{"query": {"constant_score": {"filter": {"term": {"avaliable": "false"}}}}
}POST products/_search
{"query": {"term": {"avaliable": {"value": "false"}}}
}POST products/_search
{"profile": "true","explain": true,"query": {"term": {"price": {"value": "20"}}}
}POST products/_search
{"profile": "true","explain": true,"query": {"match": {"price": "20"}}
}POST products/_search
{"query": {"constant_score": {"filter": {"bool": {"must_not": {"exists": {"field": "date"}}}}}}
}DELETE products

# boosting 查询包含以下关键元素:

# positive: 正面条件,定义了一个条件(这里是 "content": "elasticsearch"), 当文档匹配这个条件时,会增加文档的相关性得分。

# negative: 负面条件,定义了另一个条件(这里是 "content": "like"), 当文档匹配这个条件时,会减少文档的相关性得分。

# negative_boost: 这个参数指定了负面条件对得分的影响程度。在这个示例中,


DELETE testscorePUT testscore
{"settings": {"number_of_shards": 1},"mappings": {"properties": {"content": {"type": "text"}}}
}PUT testscore/_bulk
{ "index": { "_id": 1 }}
{ "content":"we use Elasticsearch to power the search" }
{ "index": { "_id": 2 }}
{ "content":"we like elasticsearch" }
{ "index": { "_id": 3 }}
{ "content":"The scoring of documents is caculated by the scoring formula" }
{ "index": { "_id": 4 }}
{ "content":"you know, for search" }# the elasticsearch会查出123条数据
# the会查出13数据
POST /testscore/_search
{//"explain": true,"query": {"match": {//"content":"you""content": "elasticsearch"//"content":"the"//"content": "the elasticsearch"}}
}# boosting 查询包含以下关键元素:
# positive: 正面条件,定义了一个条件(这里是 "content": "elasticsearch"),
#           当文档匹配这个条件时,会增加文档的相关性得分。
# negative: 负面条件,定义了另一个条件(这里是 "content": "like"),
#           当文档匹配这个条件时,会减少文档的相关性得分。
# negative_boost: 这个参数指定了负面条件对得分的影响程度。在这个示例中,
#                 设置为 0.2,表示负面条件的匹配与正面条件相比,对相关性得分的影响降低了 80%。
POST testscore/_search
{"query": {"boosting" : {"positive" : {"term" : {"content" : "elasticsearch"}},"negative" : {"term" : {"content" : "like"}},"negative_boost" : 0.2}}
}DELETE testscorePOST tmdb/_search
{"_source": ["title","overview"],"query": {"more_like_this": {"fields": ["title^10","overview"],"like": [{"_id":"14191"}],"min_term_freq": 1,"max_query_terms": 12}}
}
http://www.lryc.cn/news/478767.html

相关文章:

  • 手机屏幕上进行OCR识别方案
  • 遗传算法与深度学习实战(22)——使用Numpy构建神经网络
  • react->Antd->Table调整checkbox默认样式
  • 一种ESB的设计
  • 上位机常用通信方式
  • Vue3中使用LogicFlow实现简单流程图
  • 《重学Java设计模式》之 工厂方法模式
  • 【大数据学习 | kafka】kafka的数据存储结构
  • 知识竞赛答题系统,线上答题小程序链接怎么做?
  • 基于SSM的社区物业管理系统+LW参考示例
  • android——jetpack startup初始化框架
  • 英伟达HOVER——用于人形机器人的多功能全身控制器:整合不同的控制模式且实现彼此之间的无缝切换
  • GEE代码学习 day17
  • 论文阅读笔记-Covariate Shift: A Review and Analysis on Classifiers
  • 基于SSM+VUE守护萌宠宠物网站JAVA|VUE|Springboot计算机毕业设计源代码+数据库+LW文档+开题报告+答辩稿+部署教+代码讲解
  • 【在Linux世界中追寻伟大的One Piece】Socket编程TCP
  • 进入半导体行业需要具备哪些能力?
  • Nature重磅:AI化学家再升级!大幅提升实验效率,推动化学合成进入“智能化”新阶段
  • 源代码泄漏怎么办?SDC沙盒成为破局利器
  • 【论文复现】基于图卷积网络的轻量化推荐模型
  • 使用ssh-key免密登录服务器或免密连接git代码仓库网站
  • 自由学习记录(19)
  • Elasticsearch中时间字段格式用法详解
  • 蓝桥杯-网络安全比赛题目-遗漏的压缩包
  • ES海量数据插入如何优化性能?
  • 遥控救生圈,水上应急救援的新革命_鼎跃安全
  • 【flask开启进程,前端内容图片化并转pdf-会议签到补充】
  • Docker在CentOS上的安装与配置
  • 【笔记】开关电源变压器设计 - 工作磁通的选择原则
  • 【VScode】如何在VSCode中配置Python开发环境:从零开始的完整指南