• 改变评分查询


    Boosting query

      您可以使用提升查询来降级某些文档,而不必将它们从搜索结果中排除。

    curl -X GET "localhost:9200/_search?pretty" -H 'Content-Type: application/json' -d'
    {
      "query": {
        "boosting": {
          "positive": {
            "term": {
              "text": "apple"
            }
          },
          "negative": {
            "term": {
              "text": "pie tart fruit crumble tree"
            }
          },
          "negative_boost": 0.5
        }
      }
    }
    '
    • positive
      • required, query object. 返回的所有文档都必须与此查询匹配。
    • negative
      • required, query object. 查询用于降低匹配文档的相关性得分。
    • negative_boost
      • required, query object. 0到1.0之间的浮点数,用于降低与否定查询匹配的文档的相关性得分。

    Dis max query

      返回与一个或多个包装查询(称为查询子句或子句)匹配的文档。

      如果返回的文档与多个查询子句匹配,则dis_max查询为该文档分配来自任何匹配子句的最高相关性得分,并为任何其他匹配子查询分配平局打破增量。

      您可以使用dis_max在以不同提升因子映射的字段中搜索术语。

    curl -X GET "localhost:9200/_search?pretty" -H 'Content-Type: application/json' -d'
    {
      "query": {
        "dis_max": {
          "queries": [
            { "term": { "title": "Quick pets" } },
            { "term": { "body": "Quick pets" } }
          ],
          "tie_breaker": 0.7
        }
      }
    }
    '
    • queries
      • required, array of query objects.  包含一个或多个查询子句。返回的文档必须与这些查询中的一个或多个匹配。如果一个文档匹配多个查询,Elasticsearch将使用最高的相关性得分。
    • tie_breaker
      • optional, float. 0到1.0之间的浮点数用于增加与多个查询子句匹配的文档的相关性得分。默认值为0.0。
      • 如果tie_breaker值大于0.0,则所有匹配子句均计数,但得分最高的子句计数最高。
      • 如果文档匹配多个子句,则dis_max查询将计算该文档的相关性得分,如下所示:
        • 从具有最高分数的匹配子句中获取相关性分数。
        • 将来自其他任何匹配子句的得分乘以tie_breaker值。
        • 将最高分数加到相乘的分数上。

    would be executed as:

    curl -X GET "localhost:9200/_search?pretty" -H 'Content-Type: application/json' -d'
    {
      "query": {
        "multi_match" : {
          "query":      "Quick pets",
          "type":       "phrase_prefix",
          "fields":     [ "title", "body" ]
        }
      }
    }
    '

    Function score query

      function_score允许您修改查询检索的文档分数。例如,如果分数函数在计算上很昂贵,并且足以在过滤后的一组文档上计算分数,则此功能将非常有用。

      要使用function_score,用户必须定义​​一个查询和一个或多个函数,这些函数为查询返回的每个文档计算一个新分数。

    curl -X GET "localhost:9200/_search?pretty" -H 'Content-Type: application/json' -d'
    {
      "query": {
        "function_score": {
          "query": { "match_all": {} },
          "boost": "5",
          "random_score": {}, 
          "boost_mode": "multiply"
        }
      }
    }
    '
    GET /author/_search?pretty
    {
        "function_score": {
            "query": {
              "bool":{
                "must":[
                    {"multi_match": {"query": "", "fields":[], "type": "phrase", "slop": 3}},
                    {"multi_match": {"query": "", "fields":[], "minimum_should_match": "90%"}}
                  ],
                "must_not":[
                  { "ids":{"values":[]} }
                  ],
                "filter": [
                  {"terms": {"values": []}}
                  ]
              }
            },
            "field_value_factor": {
                "field": "score",
                "factor": 0.75,
                "modifier": "log1p",
                "missing": 0
            }
        }
    }

    https://www.elastic.co/guide/en/elasticsearch/reference/7.12/compound-queries.html

    https://www.elastic.co/guide/en/elasticsearch/reference/7.12/query-dsl-function-score-query.html

  • 相关阅读:
    hibernate自动建表时设置编码格式
    【友盟统计报表解读】之错误分析iOS版
    用vs2008和vs2005创建win32 console application
    win7 无法启动此程序,因为计算机中丢失glut32.dll
    visual studio 2005 win7 64位版下载
    win7兼容visual studio 2005 的方法
    OpenGL入门学习(一)(转)--环境搭建
    opengl教程
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1)用法
    OpenGL函数思考-glColor
  • 原文地址:https://www.cnblogs.com/Mint-diary/p/14609232.html
Copyright © 2020-2023  润新知