sree
sree

Reputation: 902

Elastic Search always returning score as zero

I ran the index and I am trying to execute few queries to validate the data. I found that whatever request I sent the elastic search score is zero for all the results. I am trying different combinations in Kibana and all are documents returned contains _score as zero. Below is my request and response:

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
}
}

Response is :

{
  "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@"
      ]
    }
  }
]
 }

} Can you point me to right direction tofix this score value. Thanks.

Upvotes: 3

Views: 3422

Answers (1)

baitmbarek
baitmbarek

Reputation: 2518

Sree, all you need is to use your match_phrase in the must clause instead of the filter

Your query part should look like this :

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

Output with 1 indexed document :

{
  "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"
          ]
        }
      }
    ]
  }
}

Upvotes: 5

Related Questions