Elasticsearch Disjunction max query 析取最大查询

Elasticsearch Disjunction max query 析取最大查询

摘要

返回一个会多个查询子句匹配的文档。如果返回的文档与多个查询子句匹配,则dis_max查询会为该文档分配来自所有查询子句的最高相关性得分,再加上其他得分的和与tie_breaker的积。
换句话说,您可以使用dis_max搜索来降低最佳匹配子句在相关性得分计算中所占的比重。

请求参数

  1. queries,必选项。包含一个或多个查询子句。返回的文档,必须匹配其中的一个或多个子句。如果一个文档匹配多个查询子句,Elasticsearch 将会使用最高的相关性得分。
  2. tie_breaker,选填项。介于0,1.0之间的浮点数。默认为0.0,用于增加,除最佳匹配子句外的其他匹配子句的占总相关性得分的比重。如果一个文档匹配多个子句,dis_max查询将计算该文档的相关性得分,如下所示:
    1. 从具有最高分数的匹配子句中获取相关性分数。
    2. 将任何其他匹配子句的分数乘以该tie_breaker值。
    3. 将最高分数加到相乘的分数上。

请求示例

可以仔细对比两次请求,得分结果的差异

/* 第一种:有tie_breaker参数 */
GET blak_new/_search
{
    "query": {
        "dis_max" : {
            "queries" : [
                { "term" : { "state" : "VA" }},
                { "term" : { "state" : "TN" }},
                {"terms": {
                  "state": [
                    "VA",
                    "TN"
                  ]
                }}
            ],
            "tie_breaker" : 0.7
        }
    }
}
/* 第二种:无tie_breaker参数 */
GET blak_new/_search
{
    "query": {
        "dis_max" : {
            "queries" : [
                { "term" : { "state" : "VA" }},
                { "term" : { "state" : "TN" }},
                {"terms": {
                  "state": [
                    "VA",
                    "TN"
                  ]
                }}
            ]
        }
    },
    "from":10
}

请求结果

/* 第一种:有tie_breaker参数 */
{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 43,
      "relation" : "eq"
    },
    "max_score" : 7.2276816,
    "hits" : [
      {
        "_index" : "blak_new",
        "_type" : "_doc",
        "_id" : "1011",
        "_score" : 7.2276816,
        "_source" : {
          "account_number" : 164,
          "balance" : 9101,
          "firstname" : "Cummings",
          "lastname" : "Holt",
          "age" : 26,
          "gender" : "F",
          "employer" : "Comtrak",
          "email" : "[email protected]",
          "city" : "Chaparrito",
          "state" : [
            "VA",
            "TN"
          ],
          "state_number" : 2
        }
      },
      {
        "_index" : "blak_new",
        "_type" : "_doc",
        "_id" : "13",
        "_score" : 4.7031746,
        "_source" : {
          "account_number" : 13,
          "balance" : 32838,
          "firstname" : "Nanette",
          "lastname" : "Bates",
          "age" : 28,
          "gender" : "F",
          "address" : "789 Madison Street",
          "employer" : "Quility",
          "email" : "[email protected]",
          "city" : "Nogal",
          "state" : "VA"
        }
      }
    ]
  }
}

/* 第二种:无tie_breaker参数 */

{
  "took" : 3,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 43,
      "relation" : "eq"
    },
    "max_score" : 4.003175,
    "hits" : [
      {
        "_index" : "blak_new",
        "_type" : "_doc",
        "_id" : "988",
        "_score" : 4.003175,
        "_source" : {
          "account_number" : 988,
          "balance" : 17803,
          "firstname" : "Lucy",
          "lastname" : "Castro",
          "age" : 34,
          "gender" : "F",
          "address" : "425 Fleet Walk",
          "employer" : "Geekfarm",
          "email" : "[email protected]",
          "city" : "Mulino",
          "state" : "VA"
        }
      },
      {
        "_index" : "blak_new",
        "_type" : "_doc",
        "_id" : "1011",
        "_score" : 4.003175,
        "_source" : {
          "account_number" : 164,
          "balance" : 9101,
          "firstname" : "Cummings",
          "lastname" : "Holt",
          "age" : 26,
          "gender" : "F",
          "employer" : "Comtrak",
          "email" : "[email protected]",
          "city" : "Chaparrito",
          "state" : [
            "VA",
            "TN"
          ],
          "state_number" : 2
        }
      }
    ]
  }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章