if (needUpsert) { XContentBuilder doc = getNewDocument(mutation.getAdditions(), informations.get(storename), ttl); update.setUpsert(doc);
.prepareUpdate(indexName, typeName, id) .setDoc(jsonMap) .setUpsert(jsonMap)
private static void test() { for (int i = 0; i < 10; i++) { Map<String, Object> json = new HashMap<String, Object>(); json.put("field", "test"); addUpdateBuilderToBulk(client.prepareUpdate(Config.indexName, Config.typeName, String.valueOf(i)).setUpsert(json)); } System.out.println(bulkRequestBuilder.numberOfActions()); }
@Override public void postPut(ObserverContext<RegionCoprocessorEnvironment> e, Put put, WALEdit edit, Durability durability) throws IOException { try { String indexId = new String(put.getRow()); NavigableMap<byte[], List<Cell>> familyMap = put.getFamilyCellMap(); Map<String, Object> json = new HashMap<String, Object>(); for (Map.Entry<byte[], List<Cell>> entry : familyMap.entrySet()) { for (Cell cell : entry.getValue()) { String key = Bytes.toString(CellUtil.cloneQualifier(cell)); String value = Bytes.toString(CellUtil.cloneValue(cell)); json.put(key, value); } } ElasticSearchOperator.addUpdateBuilderToBulk(client.prepareUpdate(Config.indexName, Config.typeName, indexId).setUpsert(json)); LOG.info("observer -- add new doc: " + indexId + " to type: " + Config.typeName); } catch (Exception ex) { LOG.error(ex); } }
/** * 通过ID查询 IndexResponse * * @param _id * @return */ public UpdateResponse upsert(String _id, String source) { EsLogUtils.info("执行增改 {}/{}?{}", this.index, this.type, source); return this.updateRequest(_id).setDoc(source, XContentType.JSON).setUpsert(source, XContentType.JSON).execute().actionGet(); }
XContentBuilder builder = getContent(mutation.getAdditions()); UpdateRequestBuilder update = client.prepareUpdate(indexName, storename, docid).setDoc(builder); if (needUpsert) update.setUpsert(builder); log.trace("Updating document {} with upsert {}", docid, needUpsert); update.execute().actionGet();
XContentBuilder builder = getContent(mutation.getAdditions(),informations.get(storename),ttl); UpdateRequestBuilder update = client.prepareUpdate(indexName, storename, docid).setDoc(builder); if (needUpsert) update.setUpsert(builder); log.trace("Updating document {} with upsert {}", docid, needUpsert); brb.add(update);
public void upsertUrlStatus(String url, String published, String source, boolean create, Enum status) throws IOException { Date now = new Date(); IndexRequestBuilder insert = getConnection().getClient() .prepareIndex(getIndex(), getType(), url) .setSource(jsonBuilder() .startObject() .field("url", url) .field("source", source) .field("created", now) .field("updated", now) .field("published", published) .field("status", String.valueOf(status)) .endObject()) .setCreate(create); UpdateRequestBuilder update = getConnection().getClient() .prepareUpdate(getIndex(), getType(), url) .setDoc(jsonBuilder() .startObject() .field("updated", now) .field("published", published) .field("status", String.valueOf(status)) .endObject()) .setUpsert(insert.request()); getConnection().getProcessor().add(create ? insert.request() : update.request()); }
.prepareUpdate(indexInfo.getIndexName(), getIdStrategy().getType(), extendedDataDocId) .setScriptedUpsert(true) .setUpsert(source) .setScript(new Script( ScriptType.STORED,
.setIndex(index) .setType(type) .setUpsert(indexRequest) .setSource(json) .setId(id)
.prepareUpdate(indexInfo.getIndexName(), getIdStrategy().getType(), extendedDataDocId) .setScriptedUpsert(true) .setUpsert(source) .setScript(new Script( ScriptType.STORED,
if (options.getUpsert() != null) builder.setUpsert(options.getUpsert().encode()); if (options.isDocAsUpsert() != null) builder.setDocAsUpsert(options.isDocAsUpsert()); if (options.isDetectNoop() != null) builder.setDetectNoop(options.isDetectNoop());