进阶-第08__深度探秘搜索技术_基于boost的细粒度搜索条件权重控制

 

需求:搜索标题中包含blob的帖子,同时呢,如果标题中包含java,hadoop或elasticsearch spark就优先搜索出来,同时呢,如果一个帖子包含spark,要比java,hadoop或elasticsearch优先搜索出来

 

知识点,搜索条件的权重,boost,可以将某个搜索条件的权重加大,此时当匹配这个搜索条件和匹配另一个搜索条件的document,计算relevance score时,匹配权重更大的搜索条件的document,relevance score会更高,当然也就会优先被返回回来

 

默认情况下,搜索条件的权重都是一样的,都是1

GET /forum/article/_search

{

  "query": {

    "bool": {

      "must": [

        {

          "match": {

            "title": "blog"

          }

        }

      ],

      "should": [

        {

          "match": {

            "title": {

              "query": "java"

            }

          }

        },

        {

          "match": {

            "title": {

              "query": "hadoop"

            }

          }

        },

        {

          "match": {

            "title": {

              "query": "elasticsearch"

            }

          }

        },

        {

          "match": {

            "title": {

              "query": "spark",

              "boost": 5

            }

          }

        }

      ]

    }

  }

}

结果:

{

  "took": 2,

  "timed_out": false,

  "_shards": {

    "total": 5,

    "successful": 5,

    "failed": 0

  },

  "hits": {

    "total": 5,

    "max_score": 1.7260925,

    "hits": [

      {

        "_index": "forum",

        "_type": "article",

        "_id": "5",

        "_score": 1.7260925,

        "_source": {

          "articleID": "DHJK-B-1395-#Ky5",

          "userID": 3,

          "hidden": false,

          "postDate": "2017-03-01",

          "tag": [

            "elasticsearch"

          ],

          "tag_cnt": 1,

          "view_cnt": 10,

          "title": "this is spark blog"

        }

      },

      {

        "_index": "forum",

        "_type": "article",

        "_id": "4",

        "_score": 1.4930474,

        "_source": {

          "articleID": "QQPX-R-3956-#aD8",

          "userID": 2,

          "hidden": true,

          "postDate": "2017-01-02",

          "tag": [

            "java",

            "elasticsearch"

          ],

          "tag_cnt": 2,

          "view_cnt": 80,

          "title": "this is java, elasticsearch, hadoop blog"

        }

      },

      {

        "_index": "forum",

        "_type": "article",

        "_id": "1",

        "_score": 0.80226827,

        "_source": {

          "articleID": "XHDK-A-1293-#fJ3",

          "userID": 1,

          "hidden": false,

          "postDate": "2017-01-01",

          "tag": [

            "java",

            "hadoop"

          ],

          "tag_cnt": 2,

          "view_cnt": 30,

          "title": "this is java and elasticsearch blog"

        }

      },

      {

        "_index": "forum",

        "_type": "article",

        "_id": "3",

        "_score": 0.5753642,

        "_source": {

          "articleID": "JODL-X-1937-#pV7",

          "userID": 2,

          "hidden": false,

          "postDate": "2017-01-01",

          "tag": [

            "hadoop"

          ],

          "tag_cnt": 1,

          "view_cnt": 100,

          "title": "this is elasticsearch blog"

        }

      },

      {

        "_index": "forum",

        "_type": "article",

        "_id": "2",

        "_score": 0.3971361,

        "_source": {

          "articleID": "KDKE-B-9947-#kL5",

          "userID": 1,

          "hidden": false,

          "postDate": "2017-01-02",

          "tag": [

            "java"

          ],

          "tag_cnt": 1,

          "view_cnt": 50,

          "title": "this is java blog"

        }

      }

    ]

  }

}

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值