【问题标题】:Elastic Search always returning score as zero弹性搜索总是返回零分数
【发布时间】:2019-12-08 22:28:17
【问题描述】:

我运行了索引,并尝试执行几个查询来验证数据。我发现无论我发送什么请求,弹性搜索分数对于所有结果都是零。我在 Kibana 中尝试不同的组合,所有返回的文档都包含 _score 为零。 以下是我的请求和回复:

GET _search
{
"version": true,
"size": 500,
"sort": [
{
  "_score": {
    "order": "desc"
  }
}
],
"_source": {
"excludes": []
},
"stored_fields": [
"*"
],
"script_fields": {},
"docvalue_fields": [],
"query": {
"bool": {
  "must": [],
  "filter": [
    {
      "match_all": {}
    },
    {
      "match_phrase": {
        "name": {
          "query": "RED"
        }
      }
    }
  ],
  "should": [],
  "must_not": []
}
},
 "highlight": {
 "pre_tags": [
  "@kibana-highlighted-field@"
],
"post_tags": [
  "@/kibana-highlighted-field@"
],
"fields": {
  "*": {}
},
"fragment_size": 2147483647
}
}

回复是:

{
  "took" : 126,
  "timed_out" : false,
  "_shards" : {
  "total" : 11,
  "successful" : 11,
  "skipped" : 0,
  "failed" : 0
},
"hits" : {
"total" : {
  "value" : 4,
  "relation" : "eq"
},
"max_score" : 0.0,
"hits" : [
  {
    "_index" : "products",
    "_type" : "product",
    "_id" : "11",
    "_version" : 3,
    "_score" : 0.0,
    "_source" : {
      "sellercode" : "1",
      "avgreviews" : 5.0,
      "saleprice" : null,
      "sellable" : null,
      "freedelivery" : false,
      "promotedprice" : null,
      "listprice" : 1200.2,
      "noofreviews" : 1,
      "outdooruse" : false,
      "warrantycode" : null,
      "australiasellable" : true,
      "newrelease" : null,
      "sku" : "VSTALDBED386_1",
      "height" : 68.0,
      "shortdescription" : "Loft Sofa Bed Wood Red Medium",
      "commercialuse" : true,
      "customisable" : true,
      "weight" : "5656.0KG",
      "typeCode" : "Bed - King Single",
      "colour" : "Red",
      "depth" : 51.0,
      "name" : "LOFT SOFA BED WOOD RED MEDIUM",
      "online" : true,
      "materialcode" : "Fabric",
      "assemblyrequired" : null,
      "category" : [ ],
      "stylecode" : "Contemporary"
    },
    "highlight" : {
      "name" : [
        "LOFT SOFA BED WOOD @kibana-highlighted-field@RED@/kibana-highlighted-field@ MEDIUM"
      ]
    }
  },
  {
    "_index" : "products",
    "_type" : "product",
    "_id" : "53",
    "_version" : 3,
    "_score" : 0.0,
    "_source" : {
      "sellercode" : "1",
      "avgreviews" : 5.0,
      "saleprice" : null,
      "sellable" : null,
      "freedelivery" : true,
      "promotedprice" : null,
      "listprice" : 9635.0,
      "noofreviews" : 1,
      "outdooruse" : false,
      "warrantycode" : null,
      "australiasellable" : true,
      "newrelease" : null,
      "sku" : "VSTALDBED393_1",
      "height" : 66.0,
      "shortdescription" : "tolix Stool Wood Red",
      "commercialuse" : false,
      "customisable" : false,
      "weight" : "6525.0KG",
      "typeCode" : "Bar Stool",
      "colour" : "Silver",
      "depth" : 25.0,
      "name" : "LILLI / TOLIX STOOL WOOD RED",
      "online" : true,
      "materialcode" : "Metal",
      "assemblyrequired" : null,
      "category" : [ ],
      "stylecode" : "Retro"
    },
    "highlight" : {
      "name" : [
        "LILLI / TOLIX STOOL WOOD @kibana-highlighted-field@RED@/kibana-highlighted-field@"
      ]
    }
  },
  {
    "_index" : "products",
    "_type" : "product",
    "_id" : "125",
    "_version" : 3,
    "_score" : 0.0,
    "_source" : {
      "sellercode" : "1",
      "avgreviews" : 3.0,
      "saleprice" : null,
      "sellable" : null,
      "freedelivery" : true,
      "promotedprice" : null,
      "listprice" : 6500.0,
      "noofreviews" : 1,
      "outdooruse" : false,
      "warrantycode" : null,
      "australiasellable" : true,
      "newrelease" : null,
      "sku" : "VSTALDBED405_1",
      "height" : 55.0,
      "shortdescription" : "Ialian Design New GasLift Chanelle Queen Size Red PU Leather Wodden 
     Bed frame",
      "commercialuse" : false,
      "customisable" : false,
      "weight" : "5693.0KG",
      "typeCode" : "Bed - Queen",
      "colour" : "red",
      "depth" : 58.0,
      "name" : "ITALIAN DESIGN NEW GASLIFT CHANELLE QUEEN SIZE RED PU LEATHER WOODEN BED FRAME",
      "online" : true,
      "materialcode" : "Timber",
      "assemblyrequired" : null,
      "category" : [ ],
      "stylecode" : "Contemporary"
    },
    "highlight" : {
      "name" : [
         "ITALIAN DESIGN NEW GASLIFT CHANELLE QUEEN SIZE @kibana-highlighted-field@RED@/kibana-highlighted-field@ PU LEATHER WOODEN BED FRAME"
      ]
    }
  },
  {
    "_index" : "products",
    "_type" : "product",
    "_id" : "707",
    "_version" : 3,
    "_score" : 0.0,
    "_source" : {
      "sellercode" : "2",
      "avgreviews" : 2.0,
      "saleprice" : null,
      "sellable" : null,
      "freedelivery" : false,
      "promotedprice" : null,
      "listprice" : 6326.0,
      "noofreviews" : 1,
      "outdooruse" : false,
      "warrantycode" : null,
      "australiasellable" : true,
      "newrelease" : null,
      "sku" : "VSTALDBED478_2",
      "height" : 36.0,
      "shortdescription" : "Leaf and Vine Rug Brown Cream red",
      "commercialuse" : false,
      "customisable" : true,
      "weight" : "6548.0KG",
      "typeCode" : "Shag Rug",
      "colour" : "Brown",
      "depth" : 47.0,
      "name" : "LEAF AND VINE RUG BROWN CREAM RED",
      "online" : true,
      "materialcode" : "Plastic",
      "assemblyrequired" : null,
      "category" : [ ],
      "stylecode" : "Contemporary"
    },
    "highlight" : {
      "name" : [
        "LEAF AND VINE RUG BROWN CREAM @kibana-highlighted-field@RED@/kibana-highlighted-field@"
      ]
    }
  }
]
 }

} 你能指出我正确的方向来修复这个分数值吗? 谢谢。

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    Sree,您只需在 must 子句中使用您的 match_phrase 而不是 filter

    您的查询部分应如下所示:

    "query": {
      "bool": {
        "must": [
          {
            "match_phrase": {
              "name": {
                "query": "RED"
              }
            }
          }
        ],
        "filter": [
          {
            "match_all": {}
          }
        ],
        "should": [],
        "must_not": []
      }
    }
    

    输出 1 个索引文档:

    {
      "took" : 7,
      "timed_out" : false,
      "_shards" : {
        "total" : 1,
        "successful" : 1,
        "skipped" : 0,
        "failed" : 0
      },
      "hits" : {
        "total" : {
          "value" : 1,
          "relation" : "eq"
        },
        "max_score" : 0.2876821,
        "hits" : [
          {
            "_index" : "someidx",
            "_type" : "_doc",
            "_id" : "c37m5W4BifZmUly9Ni-X",
            "_version" : 1,
            "_score" : 0.2876821,
            "_source" : {
              "sellercode" : "1",
              "avgreviews" : 5.0,
              "saleprice" : null,
              "sellable" : null,
              "freedelivery" : false,
              "promotedprice" : null,
              "listprice" : 1200.2,
              "noofreviews" : 1,
              "outdooruse" : false,
              "warrantycode" : null,
              "australiasellable" : true,
              "newrelease" : null,
              "sku" : "VSTALDBED386_1",
              "height" : 68.0,
              "shortdescription" : "Loft Sofa Bed Wood Red Medium",
              "commercialuse" : true,
              "customisable" : true,
              "weight" : "5656.0KG",
              "typeCode" : "Bed - King Single",
              "colour" : "Red",
              "depth" : 51.0,
              "name" : "LOFT SOFA BED WOOD RED MEDIUM",
              "online" : true,
              "materialcode" : "Fabric",
              "assemblyrequired" : null,
              "category" : [ ],
              "stylecode" : "Contemporary"
            },
            "highlight" : {
              "name" : [
                "LOFT SOFA BED WOOD @kibana-highlighted-field@RED@/kibana-highlighted-field@ MEDIUM"
              ]
            }
          }
        ]
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-16
      • 2021-07-21
      • 2017-09-23
      • 1970-01-01
      • 2018-07-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多