elasticsearch Nutch:如何向ElasticSearch提供其他字段?,elasticsearch,web-crawler,nutch,elasticsearch,Web Crawler,Nutch" /> elasticsearch Nutch:如何向ElasticSearch提供其他字段?,elasticsearch,web-crawler,nutch,elasticsearch,Web Crawler,Nutch" />

elasticsearch Nutch:如何向ElasticSearch提供其他字段?

elasticsearch Nutch:如何向ElasticSearch提供其他字段?,elasticsearch,web-crawler,nutch,elasticsearch,Web Crawler,Nutch,我正在使用Nutch1.13和ES2.4.5来抓取一个特定的网站,并构建一个Google站点搜索的替代品。我对此非常陌生,因此我与默认安装/configs/等没有太大的偏离。我猜,在一天结束时,我的ES索引中有一组标准字段: _index, _type, _id, url, title, content 还有其他一些。只有url、title和content对我有用-我只需要对我的网站进行全文搜索。但是,我希望ES中包含更多字段。例如,content-length或mime-type等-我认为N

我正在使用Nutch1.13和ES2.4.5来抓取一个特定的网站,并构建一个Google站点搜索的替代品。我对此非常陌生,因此我与默认安装/configs/等没有太大的偏离。我猜,在一天结束时,我的ES索引中有一组标准字段:

_index, _type, _id, url, title, content
还有其他一些。只有
url
title
content
对我有用-我只需要对我的网站进行全文搜索。但是,我希望ES中包含更多字段。例如,
content-length
mime-type
等-我认为Nutch在进行爬网时,应该已经在内部某个地方安装了它们。如何将它们提供给ES索引

您必须编写一个插件来添加那些用于索引的字段

您的
索引过滤器将如下所示:

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;
    }
}
您可以找到如何编写类似的插件