Package org.elasticsearch.client.action.bulk

Examples of org.elasticsearch.client.action.bulk.BulkRequestBuilder


                    if (closed) {
                        return;
                    }
                    continue;
                }
                BulkRequestBuilder bulk = client.prepareBulk();
                String lastSeq = null;
                String lineSeq = processLine(s, bulk);
                if (lineSeq != null) {
                    lastSeq = lineSeq;
                }

                // spin a bit to see if we can get some more changes
                try {
                    while ((s = stream.poll(bulkTimeout.millis(), TimeUnit.MILLISECONDS)) != null) {
                        lineSeq = processLine(s, bulk);
                        if (lineSeq != null) {
                            lastSeq = lineSeq;
                        }

                        if (bulk.numberOfActions() >= bulkSize) {
                            break;
                        }
                    }
                } catch (InterruptedException e) {
                    if (closed) {
                        return;
                    }
                }

                if (lastSeq != null) {
                    try {
                        if (logger.isTraceEnabled()) {
                            logger.trace("processing [_seq  ]: [{}]/[{}]/[{}], last_seq [{}]", riverIndexName, riverName.name(), "_seq", lastSeq);
                        }
                        bulk.add(indexRequest(riverIndexName).type(riverName.name()).id("_seq")
                                .source(jsonBuilder().startObject().startObject("couchdb").field("last_seq", lastSeq).endObject().endObject()));
                    } catch (IOException e) {
                        logger.warn("failed to add last_seq entry to bulk indexing");
                    }
                }

                try {
                    BulkResponse response = bulk.execute().actionGet();
                    if (response.hasFailures()) {
                        // TODO write to exception queue?
                        logger.warn("failed to execute" + response.buildFailureMessage());
                    }
                } catch (Exception e) {
View Full Code Here


        }
    }

    public void bulkUpdate(Collection<MyTweet> tweets, String indexName) {
        // now using bulk API instead of feeding each doc separate with feedDoc
        BulkRequestBuilder brb = client.prepareBulk();
        for (MyTweet tweet : tweets) {
            String id = Long.toString(tweet.getId());
            XContentBuilder source = createDoc(tweet);
            brb.add(Requests.indexRequest(indexName).type(getIndexType()).id(id).source(source));
        }
        if (brb.numberOfActions() > 0) {
//            System.out.println("actions:" + brb.numberOfActions());
            brb.execute().actionGet();
        }
    }
View Full Code Here

      throw new RuntimeException("bulkAddDocuments not supported on multi-index manager");
    }
    if (!docsJson.isJsonArray()) {
      throw new RuntimeException("bulkAddDocuments - not a list");
    }
    BulkRequestBuilder brb = _elasticClient.prepareBulk();
   
    JsonArray docJsonArray = docsJson.getAsJsonArray();
    for (JsonElement docJson: docJsonArray) {
      IndexRequest ir = new IndexRequest(_sIndexName);
      ir.type(_sIndexType);
      if (null != sParentId) {
        ir.parent(sParentId);
      }
      if (!bAllowOverwrite) {
        ir.opType(OpType.CREATE);
      }//TESTED
     
      // Some _id unpleasantness
      if (null != idFieldName) {
       
        String id = docJson.getAsJsonObject().get(idFieldName).getAsString();
        ir.id(id);
        ir.source(docJson.toString());
      }//TESTED
     
      brb.add(ir);
    }
    brb.setConsistencyLevel(WriteConsistencyLevel.ONE);
    return brb.execute().actionGet();
  }//TESTED (including children and id hashmap)
View Full Code Here

  public BulkResponse bulkAddDocuments(Collection<DBObject> docsJson, String idFieldName, String sParentId, boolean bAllowOverwrite)
  {
    if (null != _multiIndex) {
      throw new RuntimeException("bulkAddDocuments not supported on multi-index manager");
    }
    BulkRequestBuilder brb = _elasticClient.prepareBulk();
   
    for (DBObject docJson: docsJson) {
      IndexRequest ir = new IndexRequest(_sIndexName);
      ir.type(_sIndexType);
      if (null != sParentId) {
        ir.parent(sParentId);
      }
      if (!bAllowOverwrite) {
        ir.opType(OpType.CREATE);
      }//TESTED
     
      // Some _id unpleasantness
      if (null != idFieldName) {
       
        String id = (String) docJson.get(idFieldName);
        ir.id(id);
        ir.source(docJson.toString());
      }//TESTED
     
      brb.add(ir);
    }
    brb.setConsistencyLevel(WriteConsistencyLevel.ONE);
    return brb.execute().actionGet();
  }//TESTED (including children and id hashmap)
View Full Code Here

  public BulkResponse bulkDeleteDocuments(List<String> ids, String sParentId)
  {
    if (null != _multiIndex) {
      throw new RuntimeException("bulkDeleteDocuments not supported on multi-index manager");
    }
    BulkRequestBuilder brb = _elasticClient.prepareBulk();
    for (String id: ids) {
     
      DeleteRequest dr = new DeleteRequest(_sIndexName, _sIndexType, id);
      if (null != sParentId) {
        dr.parent(sParentId);
      }
      brb.add(dr);
    }
    brb.setConsistencyLevel(WriteConsistencyLevel.ONE);
   
    return brb.execute().actionGet();
  }//TESTED (inc children)
View Full Code Here

    _superClient.percolate(arg0, arg1);
  }

  //@Override
  public org.elasticsearch.client.action.bulk.BulkRequestBuilder prepareBulk() {
    return new BulkRequestBuilder(_superClient.prepareBulk());
  }
View Full Code Here

    _superClient.percolate(arg0, arg1);
  }

  //@Override
  public org.elasticsearch.client.action.bulk.BulkRequestBuilder prepareBulk() {
    return new BulkRequestBuilder(_superClient.prepareBulk());
  }
View Full Code Here

TOP

Related Classes of org.elasticsearch.client.action.bulk.BulkRequestBuilder

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.