@@ -0,0 +1,3051 @@
+package edu.neu.ccs.pyramid.experiment;%0A%0Aimport edu.neu.ccs.pyramid.configuration.Config;%0Aimport org.elasticsearch.action.index.IndexResponse;%0Aimport org.elasticsearch.client.Client;%0Aimport org.elasticsearch.common.xcontent.XContentBuilder;%0Aimport org.elasticsearch.common.xcontent.XContentFactory;%0Aimport org.elasticsearch.node.Node;%0A%0Aimport java.io.BufferedReader;%0Aimport java.io.File;%0Aimport java.io.FileReader;%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0Aimport static org.elasticsearch.node.NodeBuilder.nodeBuilder;%0A%0A/**%0A * index amazon_phone, class demo%0A * Created by chengli on 5/11/15.%0A */%0Apublic class Exp103 %7B%0A%0A    public static void main(String%5B%5D args) throws Exception%7B%0A        if (args.length !=1)%7B%0A            throw new IllegalArgumentException(%22please specify the config file%22);%0A        %7D%0A%0A        Config config = new Config(args%5B0%5D);%0A        System.out.println(config);%0A        String fileName = config.getString(%22input.file%22);%0A        String indexName = config.getString(%22index.name%22);%0A%0A        Node node = nodeBuilder().client(true).clusterName(config.getString(%22index.clusterName%22)).node();%0A        Client client = node.client();%0A%0A%0A        int id = 0;%0A        File file = new File(fileName);%0A        List%3CString%3E document = new ArrayList%3C%3E();%0A%0A        try(BufferedReader br = new BufferedReader(new FileReader(file))%0A        )%7B%0A            String line;%0A            while((line=br.readLine())!=null)%7B%0A                if (!line.equals(%22%22))%7B%0A                    document.add(getValue(line));%0A                %7D else %7B%0A                    System.out.println(%22id = %22+ id);%0A                    XContentBuilder builder = getBuilder(document);%0A                    IndexResponse response = client.prepareIndex(indexName, %22document%22,%22%22+id)%0A                            .setSource(builder)%0A                            .execute()%0A                            .actionGet();%0A                    id += 1;%0A                    document = new ArrayList%3C%3E();%0A                %7D%0A            %7D%0A        %7D%0A%0A%0A        node.close();%0A    %7D%0A%0A%0A%0A%0A%0A    public static XContentBuilder getBuilder(List%3CString%3E document) throws Exception%7B%0A        XContentBuilder builder = XContentFactory.jsonBuilder();%0A        builder.startObject();%0A        builder.field(%22productId%22, document.get(0));%0A        builder.field(%22title%22, document.get(1));%0A        builder.field(%22price%22,document.get(2));%0A        builder.field(%22userId%22, document.get(3));%0A        builder.field(%22profileName%22,document.get(4));%0A        builder.field(%22helpfulness_numerator%22, document.get(5).split(%22/%22)%5B0%5D);%0A        builder.field(%22helpfulness_denominator%22,document.get(5).split(%22/%22)%5B1%5D);%0A        builder.field(%22score%22, (int)Double.parseDouble(document.get(6)));%0A        builder.field(%22time%22, document.get(7));%0A        builder.field(%22summary%22,document.get(8));%0A        builder.field(%22text%22,document.get(9));%0A        builder.endObject();%0A        return builder;%0A    %7D%0A%0A    public static String getValue(String line)%7B%0A        int start = line.indexOf(%22:%22);%0A        return line.substring(start+2);%0A    %7D%0A%0A%7D%0A

index amazon_phone, class demo