理解Elasticsearch的相关性

这篇博客探讨了Elasticsearch如何进行全文搜索,通过一个查询示例展示了搜索名字为Sophiazhou时,返回结果包括SophiaZhou、SophiaWu和JohnZhou。Elasticsearch利用分词策略匹配文档,并计算相关性分数,按分数从高到低排序。这种能力使其成为强大的搜索引擎。
摘要由CSDN通过智能技术生成

Demo

搜索名字为Sophia zhou的文档

// request body
{
    "query":{
        "match":{
            "name":"Sophia zhou"
        }
    }
}

响应内容,可以很明显看到Sophia Wu和John Zhou都被查询出来了,对应的score如下

name_score
Sophia Zhou0.5753642
Sophia Wu0.2876821
John Zhou0.2876821
{
    "took": 2,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": 3,
        "max_score": 0.5753642,
        "hits": [
            {
                "_index": "corp",
                "_type": "employee",
                "_id": "2",
                "_score": 0.5753642,
                "_source": {
                    "country": "CA",
                    "name": "Sophia Zhou",
                    "hobbies": [
                        "foods",
                        "read"
                    ],
                    "age": 15
                }
            },
            {
                "_index": "corp",
                "_type": "employee",
                "_id": "1",
                "_score": 0.2876821,
                "_source": {
                    "country": "US",
                    "name": "Sophia Wu",
                    "birthday": "1631096936000",
                    "hobbies": [
                        "foods",
                        "play games",
                        "read",
                        "talk"
                    ],
                    "age": 1
                }
            },
            {
                "_index": "corp",
                "_type": "employee",
                "_id": "3",
                "_score": 0.2876821,
                "_source": {
                    "country": "CA",
                    "name": "John Zhou",
                    "hobbies": [
                        "swim",
                        "read"
                    ],
                    "birthday": 1315477736000,
                    "age": 11
                }
            }
        ]
    }
}

解释

可以理解为ES作为全文搜索引擎,会使用分词策略进行查询,Sophia zhou 会被分词为Sophia、zhou两个词,同理三条文档中的name都会被分词,例如John Zhou会被分词为John、Zhou;经过分词后ES会计算文档与查询条件的相关性,查询结果默认根据相关性倒序排列。这也就是ES适合做搜索引擎的原因之一。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值