码迷,mamicode.com
首页 > 编程语言 > 详细

elasticsearch 排序 算法

时间:2017-06-28 18:54:42      阅读:113      评论:0      收藏:0      [点我收藏+]

标签:elasticsearch 排序 算法

如何将tfidf映射到[1,3] 区间内


(1)建立映射x→arctanx,此为一一映射,把全体实数R映射到开区间(-π/2,π/2)
(2)开区间(-π/2,π/2)到开区间(0,1)只需要一个线性映射就可以,设为f(x)=ax+b,则有f(-π/2)=1且f(π/2)=3,解得a=2/π,b=2
综合一下,映射x→2(arctanx)/π+2,即把全体实数映射到(1,3)



所以表达式可以写成


 "script_score" : {

          "script" : "return atan(_score.doubleValue())*2/3.14159+2"

        }



为了只使用函数值 设置 "boost_mode": "replace",


所以整个请求如下


curl -XGET ‘http://localhost:9200/alias-product/product/_search?pretty&explain‘ -d ‘{

 "size" : 1,

  "query" : {

    "function_score" : {

      "query" : {

            "bool" : {

               "should" : [ {

                "match" : {

                  "_all" : {

                    "query" : "关键字",

                    "type" : "boolean",

                    "operator" : "AND",

    "boost": 10

                  }

                }

              }, {

                "match" : {

                  "company_name" : {

                    "query" : "五矿网络",

                    "type" : "boolean",

                    "operator" : "AND",

"boost": 10

                  }

                }

              } ],

              "minimum_should_match" : "1"

            }

      },

      "functions" : [

          {

        "script_score" : {

          "script" : "return atan(_score.doubleValue())*2/3.14159+2"

        }

      },{

          "filter" : {

          "match" : {

            "company_name" : {

              "query" : "关键字",

              "type" : "boolean",

              "operator" : "AND"

            }

          }

        },

        "weight" : 2

      }


 ],

      "score_mode" : "sum",

 "boost_mode": "replace"

    }

  },

  "aggregations" : {

    "agg" : {

      "terms" : {

        "field" : "member_id",

        "size" : 0,

        "order" : {

          "top_hit" : "desc"

        }

      },

      "aggregations" : {

        "top_hit" : {

          "max" : {

            "script" : {

              "inline" : "_score"

            }

          }

        }

      }

    }

  }

  }‘


elasticsearch 排序 算法

标签:elasticsearch 排序 算法

原文地址:http://12597095.blog.51cto.com/12587095/1942729

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!