@Override protected void internalWrite(Server server, Query query, ImmutableList<Result> results) throws Exception { for (Result result : results) { log.debug("Query result: [{}]", result); if (isNumeric(result.getValue())) { Map<String, Object> map = new HashMap<>(); map.put("serverAlias", server.getAlias()); map.put("server", server.getHost()); map.put("port", server.getPort()); map.put("objDomain", result.getObjDomain()); map.put("className", result.getClassName()); map.put("typeName", result.getTypeName()); map.put("attributeName", result.getAttributeName()); map.put("valuePath", Joiner.on('/').join(result.getValuePath())); map.put("keyAlias", result.getKeyAlias()); map.put("value", Double.parseDouble(result.getValue().toString())); map.put("timestamp", result.getEpoch()); log.debug("Insert into Elastic: Index: [{}] Type: [{}] Map: [{}]", indexName, ELASTIC_TYPE_NAME, map); Index index = new Index.Builder(map).index(indexName).type(ELASTIC_TYPE_NAME).build(); JestResult addToIndex = jestClient.execute(index); if (!addToIndex.isSucceeded()) { throw new ElasticWriterException(String.format("Unable to write entry to elastic: %s", addToIndex.getErrorMessage())); } } else { log.warn("Unable to submit non-numeric value to Elastic: [{}] from result [{}]", result.getValue(), result); } } }
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(); }
/** * @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 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(); }
@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; } };
@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()); }
@Override public boolean save(Movie movie) { Index index = new Index.Builder(movie).index(INDEX).type(TYPE).build(); try { JestResult jestResult = client.execute(index); log.info("save返回结果{}", jestResult.getJsonString()); return jestResult.isSucceeded(); } catch (IOException e) { log.error("save异常", e); return false; } }
public Index queryCreateEvent(Event event) { return new Index.Builder(event).index(connection.getIndexName()).type(ElasticConstants.TYPE_EVENT).refresh(true) .build(); }
public Index queryCreateProperty(Property<?> property) { return new Index.Builder(property).index(connection.getIndexName()).type(ElasticConstants.TYPE_PROPERTY) .refresh(true).build(); }
public Index queryCreateFeature(Feature fp) { return new Index.Builder(fp).index(connection.getIndexName()).type(ElasticConstants.TYPE_FEATURE).refresh(true) .build(); }
@Override public void saveEntity(Entity entity) { Index index = new Index.Builder(entity).index(Entity.INDEX_NAME).type(Entity.TYPE).build(); try { jestClient.execute(index); LOGGER.info("ES 插入完成"); } catch (IOException e) { e.printStackTrace(); LOGGER.error(e.getMessage()); } }
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 Object createBatchItem(String indexName, ItemSource source) { return new Index.Builder(source.getSource()) .index(indexName) .type(ACTION_TYPE) .build(); }
@Override public Object createBatchItem(String indexName, Object source) { return new Index.Builder(source) .index(indexName) .type(ACTION_TYPE) .build(); }
@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; }