@Override public void process(final InputStream in) throws IOException { String json = IOUtils.toString(in, charset) .replace("\r\n", " ").replace('\n', ' ').replace('\r', ' '); if (indexOp.equalsIgnoreCase("index")) { bulk.add(esClient.get().prepareIndex(index, docType, id) .setSource(json.getBytes(charset))); } else if (indexOp.equalsIgnoreCase("upsert")) { bulk.add(esClient.get().prepareUpdate(index, docType, id) .setDoc(json.getBytes(charset)) .setDocAsUpsert(true)); } else if (indexOp.equalsIgnoreCase("update")) { bulk.add(esClient.get().prepareUpdate(index, docType, id) .setDoc(json.getBytes(charset))); } else { throw new IOException("Index operation: " + indexOp + " not supported."); } } });
private UpdateRequestBuilder prepareIndexRequest(String indexName, DTO dto) throws JsonProcessingException { Map<String, Object> json = prepareDocument(dto); return this.client .prepareUpdate(indexName, this.configuration.getTypeFunction().apply(dto), String.valueOf(dto.getId())) .setDocAsUpsert(true).setDoc(this.objectWriter.writeValueAsString(json)); }
requestBuilder.setDocAsUpsert(true); bulkBuilder.add(requestBuilder.request());
requestBuilder.setDocAsUpsert(true); bulkBuilder.add(requestBuilder.request());
private UpdateRequestBuilder prepareUpdate(Graph graph, Element element, Authorizations authorizations) { try { IndexInfo indexInfo = addPropertiesToIndex(graph, element, element.getProperties()); XContentBuilder source = buildJsonContentFromElement(graph, element, authorizations); if (MUTATION_LOGGER.isTraceEnabled()) { MUTATION_LOGGER.trace("addElement json: %s: %s", element.getId(), source.string()); } getIndexRefreshTracker().pushChange(indexInfo.getIndexName()); return getClient() .prepareUpdate(indexInfo.getIndexName(), getIdStrategy().getType(), getIdStrategy().createElementDocId(element)) .setDocAsUpsert(true) .setDoc(source) .setRetryOnConflict(MAX_RETRIES); } catch (IOException e) { throw new VertexiumException("Could not add element", e); } }
private UpdateRequestBuilder prepareUpdate(Graph graph, Element element, Authorizations authorizations) { try { IndexInfo indexInfo = addPropertiesToIndex(graph, element, element.getProperties()); XContentBuilder source = buildJsonContentFromElement(graph, element, authorizations); if (MUTATION_LOGGER.isTraceEnabled()) { MUTATION_LOGGER.trace("addElement json: %s: %s", element.getId(), source.string()); } getIndexRefreshTracker().pushChange(indexInfo.getIndexName()); return getClient() .prepareUpdate(indexInfo.getIndexName(), getIdStrategy().getType(), getIdStrategy().createElementDocId(element)) .setDocAsUpsert(true) .setDoc(source) .setRetryOnConflict(MAX_RETRIES); } catch (IOException e) { throw new VertexiumException("Could not add element", e); } }
UpdateRequestBuilder updateRequestBuilder = getClient() .prepareUpdate(indexInfo.getIndexName(), ELEMENT_TYPE, extendedDataDocId) .setDocAsUpsert(true) .setDoc(source) .setRetryOnConflict(MAX_RETRIES);
UpdateRequestBuilder updateRequestBuilder = getClient() .prepareUpdate(indexInfo.getIndexName(), ELEMENT_TYPE, extendedDataDocId) .setDocAsUpsert(true) .setDoc(source) .setRetryOnConflict(MAX_RETRIES);
.setDocAsUpsert(true) .setDoc(source) .setRetryOnConflict(MAX_RETRIES);
.setDocAsUpsert(true) .setDoc(source) .setRetryOnConflict(MAX_RETRIES);
if (options.getDoc() != null) builder.setDoc(options.getDoc().encode()); 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()); if (options.isScriptedUpsert() != null) builder.setScriptedUpsert(options.isScriptedUpsert());