/** * Performs an index operation with a retry. * @param request The index request that we want to perform. * @param operationDescription The type of operation that we are performing. */ private void indexWithRetry(final IndexRequest request, final String operationDescription) { try { new RetryUtil<IndexResponse>().retryOnException(() -> { try { return elasticSearchClient.index(request); } catch (IOException e) { throw new RuntimeException(e); } }, null, null, RETRY_COUNT, operationDescription, "indexWithRetry"); } catch (Exception e) { Monitors.error(className, "index"); logger.error("Failed to index {} for request type: {}", request.id(), request.type(), e); } }
@Override public String index(IndexQuery query) { String documentId; IndexRequest request = prepareIndex(query); try { documentId = client.index(request).getId(); } catch (IOException e) { throw new ElasticsearchException("Error while index for request: " + request.toString(), e); } // We should call this because we are not going through a mapper. if (query.getObject() != null) { setPersistentEntityId(query.getObject(), documentId); } return documentId; }
public void createDocument(String type, String id, Map<String, Object> source) { try { if (this.instance() == null) return; IndexRequest request = new IndexRequest(name, type, id); request.source(source); client.index(request, RequestOptions.DEFAULT); } catch (IOException e) { log.error(e.getMessage()); } }
@Override public void indexSingle(String index, String id, String json) throws IOException { IndexRequest request = new IndexRequest(index, getDefaultTypeName(), id); request.source(json, XContentType.JSON); client.index(request, RequestOptions.DEFAULT); }
@Override public void indexSingle(String index, String id, String json) throws IOException { IndexRequest request = new IndexRequest(index, getDefaultTypeName(), id); request.source(json, XContentType.JSON); client.index(request, RequestOptions.DEFAULT); }
@Override public void indexSingle(String index, String id, String json) throws IOException { IndexRequest request = new IndexRequest(index, getDefaultTypeName(), id); request.source(json, XContentType.JSON); client.index(request); }
@Override public void indexSingle(String index, String type, String id, String json) throws IOException { IndexRequest request = new IndexRequest(index, type, id); request.source(json, XContentType.JSON); client.index(request); }
@Override public IndexResponse createIndex(String index, String type, String id, Object source) throws Exception{ IndexRequest request = new IndexRequest(index, type, id).source(JSON.toJSONString(source), XContentType.JSON); log.debug(request.toString()); return client().index(request); }
/** * * @param document * @return */ public String createIndex(Document document){ try { IndexRequest request = new IndexRequest(props.getIndex().getName(), props.getIndex().getType()); request.source(gson.toJson(document), XContentType.JSON); IndexResponse response = client.index(request); return response.getId(); } catch (Exception ex) { log.error("The exception was thrown in createIndex method. {} ", ex); } return null; }
@Override public IndexResponse index(IndexRequest request) { try { return client.index(request, RequestOptions.DEFAULT); } catch (ElasticsearchStatusException e) { if (RestStatus.CONFLICT.equals(e.status())) { throw new ConcurrentUpdateException(e); } throw new NuxeoException(e); } catch (IOException e) { throw new NuxeoException(e); } }
message.setBody(restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT).getId()); } else if (operation == ElasticsearchOperation.Update) { UpdateRequest updateRequest = message.getBody(UpdateRequest.class);
/** * Index a Fact into ElasticSearch. * * @param fact Fact to index * @return Indexed Fact */ public FactDocument indexFact(FactDocument fact) { if (fact == null || fact.getId() == null) return null; IndexResponse response; try { IndexRequest request = new IndexRequest(INDEX_NAME, TYPE_NAME, fact.getId().toString()) .setRefreshPolicy(isTestEnvironment ? WriteRequest.RefreshPolicy.IMMEDIATE : WriteRequest.RefreshPolicy.NONE) .source(FACT_DOCUMENT_WRITER.writeValueAsBytes(fact), XContentType.JSON); response = clientFactory.getHighLevelClient().index(request); } catch (IOException ex) { throw logAndExit(ex, String.format("Could not perform request to index Fact with id = %s.", fact.getId())); } if (response.status() != RestStatus.OK && response.status() != RestStatus.CREATED) { LOGGER.warning("Could not index Fact with id = %s.", fact.getId()); } else if (response.getResult() == DocWriteResponse.Result.CREATED) { LOGGER.info("Successfully indexed Fact with id = %s.", fact.getId()); } else if (response.getResult() == DocWriteResponse.Result.UPDATED) { LOGGER.info("Successfully re-indexed existing Fact with id = %s.", fact.getId()); } return fact; }