2017-06-16 52 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