Package org.elasticsearch.action.bulk

Examples of org.elasticsearch.action.bulk.BulkProcessor


        this.console = console;
    }

    protected void dumpRestore(Client client, Builder builder) throws IOException {

        BulkProcessor bulkProcessor = buildBulkProcessor(client);
        BufferedReader reader = null;
        try {
            FileInputStream fis = new FileInputStream(builder.path());
            reader = new BufferedReader(new InputStreamReader(fis, builder.charset()));
            String line;
            while( (line=reader.readLine()) != null) {
                indexLine(bulkProcessor, builder.index(), builder.type(), line);
            }

        } finally {
            bulkProcessor.close();
            if (reader != null) {
                reader.close();
            }
        }
    }
View Full Code Here


    }

    private ImportCounts handleFile(File file, String index, String type, int bulkSize, boolean compression) {
        if (file.isFile() && file.canRead()) {
            ImportBulkListener bulkListener = new ImportBulkListener(file.getAbsolutePath());
            BulkProcessor bulkProcessor = BulkProcessor.builder(client, bulkListener)
                    .setBulkActions(bulkSize)
                    .setBulkSize(bulkByteSize)
                    .setFlushInterval(flushInterval)
                    .setConcurrentRequests(concurrentRequests)
                    .build();
            try {
                BufferedReader r;
                if (compression) {
                    GZIPInputStream is = new GZIPInputStream(new FileInputStream(file));
                    r = new BufferedReader(new InputStreamReader(is));
                } else {
                    r = new BufferedReader(new FileReader(file));
                }
                String line;
                while ((line = r.readLine()) != null) {
                    IndexRequest indexRequest;
                    try {
                        indexRequest = parseObject(line);
                    } catch (ObjectImportException e) {
                        bulkListener.addFailure();
                        continue;
                    }
                    if (indexRequest != null) {
                        indexRequest.opType(OpType.INDEX);
                        if (index != null) {
                            indexRequest.index(index);
                        }
                        if (type != null) {
                            indexRequest.type(type);
                        }
                        if (indexRequest.type() != null && indexRequest.index() != null) {
                            bulkProcessor.add(indexRequest);
                        } else {
                            bulkListener.addFailure();
                        }
                    } else {
                        bulkListener.addInvalid();
                    }
                }
            } catch (FileNotFoundException e) {
                // Ignore not existing files, actually they should exist, as they are filtered before.
            } catch (IOException e) {
            } finally {
                bulkProcessor.close();
            }
            try {
                bulkListener.get();
            } catch (InterruptedException e1) {
            } catch (ExecutionException e1) {
View Full Code Here

TOP

Related Classes of org.elasticsearch.action.bulk.BulkProcessor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.