您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
elasticSearch映射参数boost
发布时间:2021-09-10 22:43:06编辑:雪饮阅读()
ElasticSearch中映射参数有这样一个参数boost。
那么这个参数可以在索引创建的时候一同配置映射信息时候添加上。如:
请求正文:
{
"mappings": {
"properties": {
"title": {
"type": "text",
"boost": 2
},
"content": {
"type": "text"
}
}
}
}
响应正文:
{
"acknowledged": true,
"shards_acknowledged": true,
"index": "my-index-000001"
}
那么boost的作用,就这里而言
就是单个字段可以在查询时自动提升——更多地计入相关性分数。
也就是说这里如果查询的时候title匹配的相关性占比更高,content占比则是title的一半(boost默认值1.0)。
那么也就是说查询出来的文档必须满足title匹配度高于content的匹配度,毕竟elasticSearch本就是全文搜索(匹配所有字段)。
这里官方有提到:
提升仅适用于术语查询(不提升前缀、范围和模糊查询)。
那么接下来假比如创建一个测试数据
请求正文:
{
"title":"quick brown fox", "description":"ICSE", "street":"West End",
"state":"UP", "zip":"250002", "location":[28.9926174, 77.692485], "fees":3500,
"tags":["fully computerized"], "rating":"4.5"
}
响应正文:
{
"_index": "my-index-000001",
"_type": "_doc",
"_id": "4",
"_version": 2,
"result": "updated",
"_shards": {
"total": 2,
"successful": 2,
"failed": 0
},
"_seq_no": 1,
"_primary_term": 1
}
那么接下来使用这种普通的match查询:
请求正文:
{
"query": {
"match": {
"title": {
"query": "quick brown fox"
}
}
}
}
响应正文:
{
"took": 309,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 1.7260926,
"hits": [
{
"_index": "my-index-000001",
"_type": "_doc",
"_id": "4",
"_score": 1.7260926,
"_source": {
"title": "quick brown fox",
"description": "ICSE",
"street": "West End",
"state": "UP",
"zip": "250002",
"location": [
28.9926174,
77.692485
],
"fees": 3500,
"tags": [
"fully computerized"
],
"rating": "4.5"
}
}
]
}
}
它就相当于下面这种在查询中指定某个字段的boost权重一样:
请求正文:
{
"query": {
"match": {
"title": {
"query": "quick brown fox",
"boost": 2
}
}
}
}
响应正文:
{
"took": 11,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 3.4521852,
"hits": [
{
"_index": "my-index-000001",
"_type": "_doc",
"_id": "4",
"_score": 3.4521852,
"_source": {
"title": "quick brown fox",
"description": "ICSE",
"street": "West End",
"state": "UP",
"zip": "250002",
"location": [
28.9926174,
77.692485
],
"fees": 3500,
"tags": [
"fully computerized"
],
"rating": "4.5"
}
}
]
}
}
那么这里回顾上面:
提升仅适用于术语查询(不提升前缀、范围和模糊查询)。
但是这里查询用的不是term而是match,那么我个人认为它这里所说的术语查询,应该是包含match的,大概意思就是比较精准的查询,但不一定非要term查询的意思吧。
因为这个不太好测试,暂时我这里没有什么办法证明我的猜想,所以就先这样了。
在 5.0.0 中已弃用。
不推荐使用索引时提升。相反,字段映射提升在查询时应用。对于 5.0.0 之前创建的索引,仍将在索引时应用提升。
为什么索引时间提升是一个坏主意
我们建议不要使用索引时间提升,原因如下:
您不能在没有boost重新索引所有文档的情况下更改索引时的值。
每个查询都支持查询时提升,达到相同的效果。不同之处在于您可以调整该boost值而无需重新索引。
索引时提升是以存储为norm的一部分,norm只有一个字节。这降低了字段长度归一化因子的分辨率,这可能导致低质量的相关性计算。
最后这两点,” 在 5.0.0 中已弃用”、” 为什么索引时间提升是一个坏主意”这里也只是借用官方文档原话直译后稍微调整修改了一下,自己也是理解个大概。原文参见:https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-boost.html
关键字词:elasticSearch,映射参数,boost
相关文章
- elasticSearch创建指定字段的搜索分析器(空白分析仪与
- elasticSearch为查询指定搜索分析器(stop分析器)
- elasticSearch创建指定字段分析器
- elasticSearch创建custom分析器char_filter,tokenizer
- elasticSearch创建custom分析器搭载html条带字符过滤
- elasticSearch内置分析器(停用词的使用)
- elasticSearch索引中创建自定义分析器(custom)及按分
- elasticSearch测试分析仪-标准标记器与ASCII码折叠标
- elasticSearch测试分析仪
- elasticSearch类型的自动创建、动态映射与cluster.rou