0

我正在實施自定義本機SearchScript,在查詢執行時產生一定的分數。給定術語x,腳本應該計算一個索引內文檔集的相似性度量。搜索腳本應該使用ScriptEngineService實例進行編譯和執行。然而,問題在於,如果已使用映射端點明確定義了字段,則無法在該段中找到該字段。ElasticSearch 5.5 SearchScript

@Override 
public Function<Map<String,Object>,SearchScript> compile(String scriptName, String scriptSource, Map<String, String> params) { 
    if ("script".equals(scriptSource)) { 
    return p -> new SearchScript() { 
     final String field; 
     final String term; 

     { 
     field = p.get("field").toString(); 
     term = p.get("term").toString(); 
     } 

     @Override 
     public LeafSearchScript getLeafSearchScript(LeafReaderContext context) throws IOException { 
     PostingsEnum postings = context.reader().postings(new Term(field), PostingsEnum.PAYLOAD); 
      if (postings == null) { 
      // The field has not been found within the segment. 
      return() -> 0; 
      } 

任何暗示到,爲什麼不能被發現含有特定領域沒有文件?

回答

0

你試圖做的事情是不可能的:發佈是按期限,而在這裏你試圖爲整個字段發佈發佈信息。你應該做context.reader().postings(new Term(field, term), PostingsEnum.PAYLOAD)