public List<String> bulkIndex(final List<Map.Entry<IndexSet, Message>> messageList, boolean isSystemTraffic) { if (messageList.isEmpty()) { return Collections.emptyList(); } final Bulk.Builder bulk = new Bulk.Builder(); for (Map.Entry<IndexSet, Message> entry : messageList) { final Message message = entry.getValue(); if (isSystemTraffic) { systemTrafficCounter.inc(message.getSize()); } else { outputByteCounter.inc(message.getSize()); } bulk.addAction(new Index.Builder(message.toElasticSearchObject(invalidTimestampMeter)) .index(entry.getKey().getWriteIndexAlias()) .type(IndexMapping.TYPE_MESSAGE) .id(message.getId()) .build()); } final BulkResult result = runBulkRequest(bulk.build(), messageList.size()); final List<BulkResult.BulkResultItem> failedItems = result.getFailedItems(); if (LOG.isDebugEnabled()) { LOG.debug("Index: Bulk indexed {} messages, took {} ms, failures: {}", result.getItems().size(), result, failedItems.size()); } if (!failedItems.isEmpty()) { return propagateFailure(failedItems, messageList, result.getErrorMessage()); } else { return Collections.emptyList(); } }
public Index prepareIndexRequest(String index, Map<String, Object> source, String id) { source.remove(Message.FIELD_ID); return new Index.Builder(source) .index(index) .type(IndexMapping.TYPE_MESSAGE) .id(id) .build(); }
private Index indexDocument(Map<String, String> indexInformation, Object source) { if (!indexInformation.containsKey(INDEX_NAME_ELEMENT)) { throw new IllegalArgumentException("Missing index name element in " + indexInformation); } final Index.Builder createIndexBuilder = new Index.Builder(source) .index(indexInformation.get(INDEX_NAME_ELEMENT)); if (indexInformation.containsKey(INDEX_TYPE_ELEMENT)) { createIndexBuilder.type(indexInformation.get(INDEX_TYPE_ELEMENT)); } if (indexInformation.containsKey(INDEX_ID_ELEMENT)) { createIndexBuilder.id(indexInformation.get(INDEX_ID_ELEMENT)); } return createIndexBuilder.build(); }
/** * Stores a "dataversion" record in the ES store. There is only a single one of these. The * return value of the add will include the version number of the entity. This version * number is what we use to determine whether our cache is stale. */ protected void updateDataVersion() { DataVersionBean dv = new DataVersionBean(); dv.setUpdatedOn(System.currentTimeMillis()); Index index = new Index.Builder(dv).refresh(false) .index(getDefaultIndexName()) .type("dataVersion").id("instance").build(); //$NON-NLS-1$ //$NON-NLS-2$ getClient().executeAsync(index, new JestResultHandler<JestResult>() { @Override public void completed(JestResult result) { dataVersion = null; } @Override public void failed(Exception e) { dataVersion = null; } }); }
/** * Updates a single entity. * @param type * @param id * @param source * @throws StorageException */ private void updateEntity(String type, String id, XContentBuilder source) throws StorageException { try { String doc = source.string(); /* JestResult response = */esClient.execute(new Index.Builder(doc) .setParameter(Parameters.OP_TYPE, "index").index(getIndexName()).type(type).id(id).build()); //$NON-NLS-1$ } catch (Exception e) { throw new StorageException(e); } }
/** * @see io.apiman.gateway.engine.components.ICacheStoreComponent#put(java.lang.String, java.lang.Object, long) */ @Override public <T> void put(String cacheKey, T jsonObject, long timeToLive) throws IOException { ESCacheEntry entry = new ESCacheEntry(); entry.setData(null); entry.setExpiresOn(System.currentTimeMillis() + (timeToLive * 1000)); entry.setHead(mapper.writeValueAsString(jsonObject)); Index index = new Index.Builder(entry).refresh(false).index(getIndexName()) .type("cacheEntry").id(cacheKey).build(); //$NON-NLS-1$ try { getClient().execute(index); } catch (Throwable e) { } }
private Map<IndexId, Index> indexRequests(Node node) { HashMap<IndexId, Index> reqs = new HashMap<>(); for (Label l: node.getLabels()) { if (!indexLabels.contains(l.name())) continue; for (ElasticSearchIndexSpec spec: indexSettings.getIndexSpec().get(l.name())) { String id = id(node), indexName = spec.getIndexName(); reqs.put(new IndexId(indexName, id), new Index.Builder(nodeToJson(node, spec.getProperties())) .type(l.name()) .index(indexName) .id(id) .build()); } } return reqs; }
/** * Updates a single entity. * @param type * @param id * @param source * @throws StorageException */ private void updateEntity(String type, String id, XContentBuilder source) throws StorageException { try { String doc = source.string(); /* JestResult response = */esClient.execute(new Index.Builder(doc) .setParameter(Parameters.OP_TYPE, "index").index(getIndexName()).type(type).id(id).build()); //$NON-NLS-1$ } catch (Exception e) { throw new StorageException(e); } }
/** * @see io.apiman.gateway.engine.components.ICacheStoreComponent#put(java.lang.String, java.lang.Object, long) */ @Override public <T> void put(String cacheKey, T jsonObject, long timeToLive) throws IOException { ESCacheEntry entry = new ESCacheEntry(); entry.setData(null); entry.setExpiresOn(System.currentTimeMillis() + (timeToLive * 1000)); entry.setHead(mapper.writeValueAsString(jsonObject)); Index index = new Index.Builder(entry).refresh(false).index(getIndexName()) .type("cacheEntry").id(cacheKey).build(); //$NON-NLS-1$ try { getClient().execute(index); } catch (Throwable e) { } }
@Override public void end() { if (!aborted) { entry.setData(Base64.encodeBase64String(data.getBytes())); Index index = new Index.Builder(entry).refresh(false).index(getIndexName()) .type("cacheEntry").id(cacheKey).build(); //$NON-NLS-1$ try { getClient().execute(index); } catch (Throwable e) { } } finished = true; } };
public Builder(Object source) { this.source = source; this.id(getIdFromSource(source)); // set the default for id if it exists in source }
@Override public void end() { if (!aborted) { entry.setData(Base64.encodeBase64String(data.getBytes())); Index index = new Index.Builder(entry).refresh(false).index(getIndexName()) .type("cacheEntry").id(cacheKey).build(); //$NON-NLS-1$ try { getClient().execute(index); } catch (Throwable e) { } } finished = true; } };
/** * The index function will take as arguments indexName, documentType, id, json and add the document to the index. */ @Override public final void createIndexDocument(String indexName, String documentType, String id, String json) { Index index = new Index.Builder(json).index(indexName).type(documentType).id(id).build(); JestResult jestResult = jestClientHelper.execute(index); LOGGER.info("Creating Index Document, indexName={}. successful is {}", indexName, jestResult.isSucceeded()); }
public Builder(Object source) { this.source = source; this.id(getIdFromSource(source)); // set the default for id if it exists in source }
public Index prepareIndexRequest(String index, Map<String, Object> source, String id) { source.remove(Message.FIELD_ID); return new Index.Builder(source) .index(index) .type(IndexMapping.TYPE_MESSAGE) .id(id) .setParameter(Parameters.CONSISTENCY, "one") .build(); }
/** * The index function will take as arguments indexName, documentType, id, json and add the document to the index. */ @Override public final void createIndexDocument(String indexName, String documentType, String id, String json) { Index index = new Index.Builder(json).index(indexName).type(documentType).id(id).build(); JestResult jestResult = jestClientHelper.execute(index); LOGGER.info("Creating Index Document, indexName={}. successful is {}", indexName, jestResult.isSucceeded()); }
@Override public BulkableAction<DocumentResult> addElement(E element, boolean create) { Document document = toDocument(element); if (document == null) return null; Index.Builder builder = new Index.Builder(document.getFields()) .index(document.getIndex()) .type(document.getType()) .id(document.getId()); return builder.build(); }
public Index queryUpdateFeature(Feature fp) { return new Index.Builder(fp).index(connection.getIndexName()).type(ElasticConstants.TYPE_FEATURE) .id(getFeatureTechId(fp.getUid())).refresh(true).build(); }
private Action<?> indexDocument(String id, Document document, Class<?> entityType, boolean refresh) { JsonObject source = convertToJson( document, entityType ); String type = entityType.getName(); Index index = new Index.Builder( source ) .index( indexName ) .type( type ) .id( id ) .refresh( refresh ) .build(); return index; }
public Builder(Object source) { this.source = source; this.id(getIdFromSource(source)); // set the default for id if it exists in source }