2017-08-15 27 views
0

運行鶺鴒網站(1.11)與elasticsearch(5.5)作爲搜索後端和索引多個字段,例如命中領域:如何檢索這引發了elasticsearch查詢

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'), 
] 

我想指出在哪個字段中,搜索在我的搜索結果模板中出現了「點擊」(或者甚至更好地顯示點擊的片段,但似乎是另一個問題)。

This question似乎解決了我的問題,但我不知道如何將它集成到我的w site站點。

任何提示如何獲得這些信息,以及如何將其整合到w search搜索中?

回答

1

ElasticSearch具有Explain API,它可以解釋如何使用特定ID爲特定記錄按內容對字段進行內部打分。

下面是文檔:

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

它絕對讓你在每場是如何提振和分數是如何構建一個答案。

例如,如果您的匹配max_score爲2.0588222,並且您想知道哪些字段對此分數有貢獻,則可以使用explain API。

這是一個解釋查詢響應的例子,你看到的那場貢獻的firstName到1.2321436最高得分和lastName貢獻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 as 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 as (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 as 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 as (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" : [ ] 
     } ] 
     } ] 
    } ] 
    } 
} 

關於鶺鴒:我與它沒有任何經驗。但是,您絕對可以訪問REST API並解析Explain查詢的JSON。

+0

這聽起來很棒@ gil.fernandes - 但我不知道如何使用這個特性使用內置的_wagtail作爲後端搜索的elasticsearch,如果有人能指點我的示例實現 – tombreit

相關問題