@Override public long getNextLong(String sequenceName) { String source = "{ \"ts\" : " + System.currentTimeMillis() + "}"; IndexResponse res = esClient.index( new IndexRequest(indexName, ElasticSearchConstants.SEQ_ID_TYPE, sequenceName).source(source, XContentType.JSON)); return res.getVersion(); }
@Override public void initSequence(String key, long id) { String source = "{ \"ts\" : " + System.currentTimeMillis() + "}"; IndexResponse res = esClient.index( new IndexRequest(indexName, ElasticSearchConstants.SEQ_ID_TYPE, key).versionType(VersionType.EXTERNAL) .version(id) .source(source, XContentType.JSON)); }
void processIndexCommand(IndexingCommand cmd) { IndexRequest request; try { request = buildEsIndexingRequest(cmd); } catch (BlobNotFoundException pe) { request = null; } catch (DocumentNotFoundException e) { request = null; } catch (IllegalStateException e) { log.error("Fail to create request for indexing command: " + cmd, e); return; } if (request == null) { log.info("Cancel indexing command because target document does not exists anymore: " + cmd); return; } if (log.isDebugEnabled()) { logDebugMessageTruncated(String.format("Index request: curl -XPUT 'http://localhost:9200/%s/%s/%s' -d '%s'", getWriteIndexForRepository(cmd.getRepositoryName()), DOC_TYPE, cmd.getTargetDocumentId(), request.toString()), MAX_CURL_LINE); } try { esa.getClient().index(request); } catch (ConcurrentUpdateException e) { SequenceTracer.addNote("Ignore indexing of doc " + cmd.getTargetDocumentId()); log.info("Ignore indexing of doc " + cmd.getTargetDocumentId() + " a more recent version has already been indexed: " + e.getMessage()); } }