如何将实际分数实现为0,然后仅将功能分数值应用于elasticsearch

时间:2016-12-08 06:03:17

标签: elasticsearch scoring

以下是申请自定义分数的代码,它给出旧分数+自定义分数的总和。如何删除旧分数但实际放置功能计算的分数?

{
  "query": {
    "function_score": {
      "query": {
        "bool": {
          "must": [
            {
              "match": {
                "search_title": "apple iphone 6s"
              }
            },
            {
              "match": {
                "in_search": "1"
              }
            },
            {
              "match": {
                "prod_id_active": 1
              }
            }
          ]
        }
      },
      "functions": [
        {
          "filter": {
            "match": {
              "search_title": "apple iphone 6s"
            }
          },
          "script_score": {
            "params": {
              "possibility_rank": 7,
              "max_cat_rank": 5000,
              "max_prod_rank": 10000
            },
            "script": "return possibility_rank * (max_cat_rank + max_prod_rank)-(doc['category_rank'].value + doc['product_rank'].value)"
          }
        },
        {
          "filter": {
            "match": {
              "search_title": "apple iphone"
            }
          },
          "script_score": {
            "params": {
              "possibility_rank": 6,
              "max_cat_rank": 5000,
              "max_prod_rank": 10000
            },
            "script": "return possibility_rank * (max_cat_rank + max_prod_rank)-(doc['category_rank'].value + doc['product_rank'].value)"
          }
        },
        {
          "filter": {
            "match": {
              "search_title": "apple 6s"
            }
          },
          "script_score": {
            "params": {
              "possibility_rank": 5,
              "max_cat_rank": 5000,
              "max_prod_rank": 10000
            },
            "script": "return possibility_rank * (max_cat_rank + max_prod_rank)-(doc['category_rank'].value + doc['product_rank'].value)"
          }
        },
        {
          "filter": {
            "match": {
              "search_title": "iphone 6s"
            }
          },
          "script_score": {
            "params": {
              "possibility_rank": 4,
              "max_cat_rank": 5000,
              "max_prod_rank": 10000
            },
            "script": "return possibility_rank * (max_cat_rank + max_prod_rank)-(doc['category_rank'].value + doc['product_rank'].value)"
          }
        },
        {
          `entercodehere`"filter": {
            "match": {
              "search_title": "apple"
            }
          },
          "script_score": {
            "params": {
              "possibility_rank": 3,
              "max_cat_rank": 5000,
              "max_prod_rank": 10000
            },
            "script": "return possibility_rank * (max_cat_rank + max_prod_rank)-(doc['category_rank'].value + doc['product_rank'].value)"
          }
        },
        {
          "filter": {
            "match": {
              "search_title": "iphone"
            }
          },
          "script_score": {
            "params": {
              "possibility_rank": 2,
              "max_cat_rank": 5000,
              "max_prod_rank": 10000
            },
            "script": "return possibility_rank * (max_cat_rank + max_prod_rank)-(doc['category_rank'].value + doc['product_rank'].value)"
          }
        },
        {
          "filter": {
            "match": {
              "search_title": "apple watch"
            }
          },
          "script_score": {
            "params": {
              "possibility_rank": 1,
              "max_cat_rank": 5000,
              "max_prod_rank": 10000
            },
            "script": "return possibility_rank * (max_cat_rank + max_prod_rank)-(doc['category_rank'].value + doc['product_rank'].value)"
          }
        }
      ],
      "score_mode": "sum"
    }
  }
}

0 个答案:

没有答案