2017-06-16 19 views
0

我使用Nutch的1.13和ES 2.4.5抓取特定網站,並建立一個替代谷歌網站搜索的。我很新,所以我沒有偏離默認的安裝/配置/等。在一天結束的時候,我有,我想,一組標準字段在我的ES指數:Nutch的:如何給更多的領域ElasticSearch?

_index, _type, _id, url, title, content 

和其他幾個人。只有urltitlecontent對我來說是有用的 - 我只需要爲我的網站全文搜索。但是,我希望在ES中包含更多的字段。例如,content-lengthmime-type等 - 我相信Nutch的應該讓他們已經在內部的某個地方,做爬行時。如何將它們提供給ES索引?

回答

0

你必須寫一個IndexingFilter插件添加這些字段建立索引。

IndexingFilter會是這個樣子:

public class AddField implements IndexingFilter { 

    private Configuration conf; 

    public NutchDocument filter(NutchDocument doc, Parse parse, Text url, 
      CrawlDatum datum, Inlinks inlinks) { 
     String content = parse.getText(); 
     doc.add("pageLength", content.length()); 
     // add more field 
     // ... 

     return doc; 
    } 

    //Boilerplate 
    public Configuration getConf() { 
     return conf; 
    } 

    //Boilerplate 
    public void setConf(Configuration conf) { 
     this.conf = conf; 
    } 
} 

你可以找到如何寫一個類似的插件here