django - How to retrieve the field which triggered a hit for a elasticsearch query -


running wagtail site (1.11) elasticsearch (5.5) search backend , indexing multiple fields, e.g.:

search_fields = page.search_fields + [     index.searchfield('body'),     index.searchfield('get_post_type_display'),     index.searchfield('document_excerpt', boost=2),     index.searchfield('get_dark_data_full_text'), ] 

i indicate in field search lands 'hit' in search results template (or better display snippet of hit, seems question).

this question seem address issue, don't know how integrate in wagtail site.

any tips how information , how integrate in wagtail search?

elasticsearch has explain api can explain how internally scores hits field specific record specific id.

here documentation:

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-explain.html

it gives answer on how each field boosted , how score built.

for example, if hits max_score 2.0588222 , want know how fields contributed score, can use explain api.

this example of explain query response see field firstname contributed 1.2321436 max score , lastname contributed 0.8266786:

{   "_index" : "customer_test",   "_type" : "customer",   "_id" : "597f2b3a79c404fafefcd46e",   "matched" : true,   "explanation" : {     "value" : **2.0588222**,     "description" : "sum of:",     "details" : [ {       "value" : 2.0588222,       "description" : "sum of:",       "details" : [ {         "value" : **1.2321436**,         "description" : "weight(firstname:merge in 23) [perfieldsimilarity], result of:",         "details" : [ {           "value" : 1.2321436,           "description" : "score(doc=23,freq=1.0 = termfreq=1.0\n), product of:",           "details" : [ {             "value" : 1.2321436,             "description" : "idf, computed log(1 + (doccount - docfreq + 0.5) / (docfreq + 0.5)) from:",             "details" : [ {               "value" : 3.0,               "description" : "docfreq",               "details" : [ ]             }, {               "value" : 11.0,               "description" : "doccount",               "details" : [ ]             } ]           }, {             "value" : 1.0,             "description" : "tfnorm, computed (freq * (k1 + 1)) / (freq + k1 * (1 - b + b * fieldlength / avgfieldlength)) from:",             "details" : [ {               "value" : 1.0,               "description" : "termfreq=1.0",               "details" : [ ]             }, {               "value" : 1.2,               "description" : "parameter k1",               "details" : [ ]             }, {               "value" : 0.75,               "description" : "parameter b",               "details" : [ ]             }, {               "value" : 1.0,               "description" : "avgfieldlength",               "details" : [ ]             }, {               "value" : 1.0,               "description" : "fieldlength",               "details" : [ ]             } ]           } ]         } ]       }, {         "value" : 0.8266786,         "description" : "weight(lastname:doe in 23) [perfieldsimilarity], result of:",         "details" : [ {           "value" : 0.8266786,           "description" : "score(doc=23,freq=1.0 = termfreq=1.0\n), product of:",           "details" : [ {             "value" : **0.8266786**,             "description" : "idf, computed log(1 + (doccount - docfreq + 0.5) / (docfreq + 0.5)) from:",             "details" : [ {               "value" : 3.0,               "description" : "docfreq",               "details" : [ ]             }, {               "value" : 7.0,               "description" : "doccount",               "details" : [ ]             } ]           }, {             "value" : 1.0,             "description" : "tfnorm, computed (freq * (k1 + 1)) / (freq + k1 * (1 - b + b * fieldlength / avgfieldlength)) from:",             "details" : [ {               "value" : 1.0,               "description" : "termfreq=1.0",               "details" : [ ]             }, {               "value" : 1.2,               "description" : "parameter k1",               "details" : [ ]             }, {               "value" : 0.75,               "description" : "parameter b",               "details" : [ ]             }, {               "value" : 1.0,               "description" : "avgfieldlength",               "details" : [ ]             }, {               "value" : 1.0,               "description" : "fieldlength",               "details" : [ ]             } ]           } ]         } ]       } ]     }, {       "value" : 0.0,       "description" : "match on required clause, product of:",       "details" : [ {         "value" : 0.0,         "description" : "# clause",         "details" : [ ]       }, {         "value" : 1.0,         "description" : "_type:customer, product of:",         "details" : [ {           "value" : 1.0,           "description" : "boost",           "details" : [ ]         }, {           "value" : 1.0,           "description" : "querynorm",           "details" : [ ]         } ]       } ]     } ]   } } 

about wagtail: have no experience it. can access rest api , parse json of explain query.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -