elasticsearchClient.prepareIndex(indexName, be.type, be.id).setSource(be.jsonMap) .setVersion(1) .setCreate(false) // enforces OpType.INDEX .setVersionType(VersionType.EXTERNAL_GTE));
public void addElement(Element element, String index, String routing, boolean create) { IndexRequestBuilder indexRequest = client.prepareIndex(index, element.label(), element.id().toString()) .setSource(propertiesMap(element)).setRouting(routing).setCreate(create); if(bulkRequest != null) bulkRequest.add(indexRequest); else indexRequest.execute().actionGet(); revision++; }
/** * Index one entity model by its type. Return error if an entity model already exists for that entity type. * * @param entityType The entity type. * @param requestBody The request body. * @param client The client that will communicate with Elasticsearch. * @return The response from Elasticsearch. * @throws ForbiddenException */ public static IndexResponse indexEntityModel(String entityType, String requestBody, NodeClient client) throws ForbiddenException { ensureIndex(client); IndexRequestBuilder request = client.prepareIndex(INDEX_NAME, "doc", entityType); request.setSource(requestBody, XContentType.JSON).setCreate(true).setRefreshPolicy("wait_for"); return request.get(); }
/** * Update one entity model by its type. Does not support partial updates. * * @param entityType The entity type. * @param requestBody The request body. * @param client The client that will communicate with Elasticsearch. * @return The response from Elasticsearch. * @throws ForbiddenException */ public static IndexResponse updateEntityModel(String entityType, String requestBody, NodeClient client) throws ForbiddenException { ensureIndex(client); IndexRequestBuilder request = client.prepareIndex(INDEX_NAME, "doc", entityType); request.setSource(requestBody, XContentType.JSON).setCreate(false).setRefreshPolicy("wait_for"); return request.get(); }
indexRequestBuilder.setCreate(create);
indexRequestBuilder.setCreate(create);
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()); }
.setCreate(forceCreate) .setSource(source); if (!entity.isNew() && performVersionCheck) {
.setCreate(forceCreate) .setSource(source); if (!entity.isNew() && performVersionCheck) {