Search in sources :

Example 1 with IndexRequestBuilder

use of org.elasticsearch.client.action.index.IndexRequestBuilder in project nutch-elasticsearch-indexer by ctjmorgan.

the class ElasticsearchWriter method write.

@Override
public void write(NutchDocument doc) throws IOException {
    // Set up the es index response 
    String uuid = UUID.randomUUID().toString();
    IndexRequestBuilder response = client.prepareIndex("nutch", "index", uuid);
    Map<String, Object> mp = new HashMap<String, Object>();
    for (final Entry<String, NutchField> e : doc) {
        for (final Object val : e.getValue().getValues()) {
            String key;
            // normalise the string representation for a Date
            Object val2 = val;
            if (val instanceof Date) {
                key = e.getKey();
                val2 = DateUtil.getThreadLocalDateFormat().format(val);
                mp.put(key, val2);
            } else {
                key = e.getKey();
                mp.put(key, val);
            }
        }
    }
    // insert the document into elasticsearch
    response.setSource(mp);
    response.execute();
}
Also used : IndexRequestBuilder(org.elasticsearch.client.action.index.IndexRequestBuilder) NutchField(org.apache.nutch.indexer.NutchField) HashMap(java.util.HashMap) Date(java.util.Date)

Aggregations

Date (java.util.Date)1 HashMap (java.util.HashMap)1 NutchField (org.apache.nutch.indexer.NutchField)1 IndexRequestBuilder (org.elasticsearch.client.action.index.IndexRequestBuilder)1