How to score result in elasticsearch?


(Ngọc Phạm) #1

sorry for my newbie question, i dont know how elasticsearch score result :smile:

i read in https://www.elastic.co/guide/en/elasticsearch/guide/current/scoring-theory.html it have :

tf(t in d) = √frequency 
idf(t) = 1 + log ( numDocs / (docFreq + 1)) 
norm(d) = 1 / √numTerms  

In java, i try search and setExplain(True). My respone is....

{
  "took" : 3,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 61,
    "max_score" : 2.8814154,
    "hits" : [ {
      "_shard" : 1,
      "_node" : "aJhrjUCeQsWLNYjFTHmufw",
      "_index" : "products",
      "_type" : "product",
      "_id" : "288",
      "_score" : 2.8814154,
      "_source":{"products_id":288,"products_code":"61-65SP287","categories_id":61,"manufacturers_id":65,"users_id":1,"users_fullname":"hong luu","products_title":"Modem Dlink DSL-526E","products_alias":"Modem-Dlink-DSL-526E","products_description":"<table width=\"692\"> \n <tbody> \n  <tr> \n   <td width=\"177\">Sản phẩm</td> \n   <td width=\"515\">Modem</td> \n  </tr> \n  <tr> \n   <td>Hãng sản xuất</td> \n   <td>Dlink</td> \n  </tr> \n  <tr> \n   <td>Model</td> \n   <td>DSL-526E</td> \n  </tr> \n  <tr> \n   <td>Tốc độ LAN</td> \n   <td>10/100Mbps</td> \n  </tr> \n  <tr> \n   <td>Cổng giao tiếp</td> \n   <td>1 cổng LAN 10/100Mbps, 1 cổng WAN</td> \n  </tr> \n  <tr> \n   <td>Mô tả khác</td> \n   <td>&nbsp;Hỗ trợ dịch vụ myTV, DHCP, NAT, DMZ, Firewall. Hỗ trợ bộ nhớ cao 16MB -&nbsp; tạo 8 kênh riêng ảo (PVC)</td> \n  </tr> \n </tbody> \n</table>","seo_keywords":null,"seo_description":null,"seo_title":null,"is_published":1,"is_delete":0,"is_new":false,"is_hot":true,"is_available":true,"date_create":"2015-11-02 21:10:22 +0700","date_update":"2015-11-02 21:10:22 +0700","price":275000,"price_sale":0,"ordering":1,"quantity":10,"thumb_image":"/media/product/13526_16999_0a9ff6cf226e224b7fd33a68943b5cc2.jpg","number_views":0,"vat":10,"rating":0.0,"number_like":0,"total_sale":0,"bao_hanh":24,"product_banner":null,"manufacturers_name":"Dlink","@version":"1","@timestamp":"2015-11-10T03:08:42.205Z"},
      "_explanation" : {
        "value" : 2.8814154,
        "description" : "weight(products_title:dlink in 56) [PerFieldSimilarity], result of:",
        "details" : [ {
          "value" : 2.8814154,
          "description" : "score(doc=56,freq=1.0), product of:",
          "details" : [ {
            "value" : 0.99999994,
            "description" : "queryWeight, product of:",
            "details" : [ {
              "value" : 5.762831,
              "description" : "idf(docFreq=12, maxDocs=1522)"
            }, {
              "value" : 0.17352581,
              "description" : "queryNorm"
            } ]
          }, {
            "value" : 2.8814156,
            "description" : "fieldWeight in 56, product of:",
            "details" : [ {
              "value" : 1.0,
              "description" : "tf(freq=1.0), with freq of:",
              "details" : [ {
                "value" : 1.0,
                "description" : "termFreq=1.0"
              } ]
            }, {
              "value" : 5.762831,
              "description" : "idf(docFreq=12, maxDocs=1522)"
            }, {
              "value" : 0.5,
              "description" : "fieldNorm(doc=56)"
            } ]
          } ]
        } ]
      }
    } 

My example have 7620 record , i used plugin https://github.com/jprante/elasticsearch-index-termlist , it have

 "took" : 610,
  "numdocs" : 7620,
  "numterms" : 33407,

Who know please explain how to score it :slight_smile: . Pls show me how it math :X
Thanks you very much


(Ngọc Phạm) #2

Anybody please help me know what exactly elasticsearch score T_T ?

Thanks you


(Trần Thanh Bảo) #3

What do you mean of "score result" exactly, time of searching query or something else ?
ps: mình cũng mới tình hiểu dc 2 tuần ,~(‾▿‾)~


(Ngọc Phạm) #4

"exactly" that mean algorithm elasticsearch use for scoring in .setExplain(true) in java.

i use algorithm write in guide elasticsearch, but it not true with my example. i dont know how it work

Thus, i want anybody know that please explain to me " How elasticsearch Scoring " in my example (or any example its ok, i only want know how it working,what is numDocs, docFreq in .setExplain(true) ).

Thanks for your help !

p/s: You can pm me if want speak our language @tranthanhbao2207 :))


(system) #5