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(); }
indexBuilder.setParameter(Parameters.VERSION, query.getVersion()); indexBuilder.setParameter(Parameters.VERSION_TYPE, EXTERNAL.name().toLowerCase()); indexBuilder.setParameter(Parameters.PARENT, query.getParentId());
builder.setParameter(Parameters.VERSION, String.valueOf(version)); Index index = builder.setParameter(Parameters.OP_TYPE, "index") //$NON-NLS-1$ .type("rateBucket").id(id).build(); //$NON-NLS-1$ try {
builder.setParameter(Parameters.VERSION, String.valueOf(version)); Index index = builder.setParameter(Parameters.OP_TYPE, "index") //$NON-NLS-1$ .type("rateBucket").id(id).build(); //$NON-NLS-1$ try {
/** * @see io.apiman.gateway.engine.IRegistry#registerClient(io.apiman.gateway.engine.beans.Client, io.apiman.gateway.engine.async.IAsyncResultHandler) */ @Override public void registerClient(final Client client, final IAsyncResultHandler<Void> handler) { try { // Validate the client and populate the api map with apis found during validation. validateClient(client); String id = getClientId(client); Index index = new Index.Builder(client) .refresh(false) .index(getIndexName()) .setParameter(Parameters.OP_TYPE, "index") //$NON-NLS-1$ .type("client") //$NON-NLS-1$ .id(id) .build(); JestResult result = getClient().execute(index); if (!result.isSucceeded()) { throw new IOException(result.getErrorMessage()); } else { handler.handle(AsyncResultImpl.create((Void) null)); } } catch (IOException e) { handler.handle(AsyncResultImpl.create( new RegistrationException(Messages.i18n.format("ESRegistry.ErrorRegisteringClient"), e), //$NON-NLS-1$ Void.class)); } catch (RuntimeException re) { handler.handle(AsyncResultImpl.create(re, Void.class)); } }
/** * @see io.apiman.gateway.engine.IRegistry#registerClient(io.apiman.gateway.engine.beans.Client, io.apiman.gateway.engine.async.IAsyncResultHandler) */ @Override public void registerClient(final Client client, final IAsyncResultHandler<Void> handler) { try { // Validate the client and populate the api map with apis found during validation. validateClient(client); String id = getClientId(client); Index index = new Index.Builder(client) .refresh(false) .index(getIndexName()) .setParameter(Parameters.OP_TYPE, "index") //$NON-NLS-1$ .type("client") //$NON-NLS-1$ .id(id) .build(); JestResult result = getClient().execute(index); if (!result.isSucceeded()) { throw new IOException(result.getErrorMessage()); } else { handler.handle(AsyncResultImpl.create((Void) null)); } } catch (IOException e) { handler.handle(AsyncResultImpl.create( new RegistrationException(Messages.i18n.format("ESRegistry.ErrorRegisteringClient"), e), //$NON-NLS-1$ Void.class)); } catch (RuntimeException re) { handler.handle(AsyncResultImpl.create(re, Void.class)); } }
/** * Indexes an entity. * @param type * @param id * @param sourceEntity * @param refresh true if the operation should wait for a refresh before it returns * @throws StorageException */ @SuppressWarnings("nls") private void indexEntity(String type, String id, XContentBuilder sourceEntity, boolean refresh) throws StorageException { try { String json = sourceEntity.string(); JestResult response = esClient.execute(new Index.Builder(json).refresh(refresh).index(getIndexName()) .setParameter(Parameters.OP_TYPE, "create").type(type).id(id).build()); if (!response.isSucceeded()) { throw new StorageException("Failed to index document " + id + " of type " + type + ": " + response.getErrorMessage()); } } catch (StorageException e) { throw e; } catch (Exception e) { throw new StorageException(e); } }
/** * @see io.apiman.gateway.engine.IRegistry#publishApi(io.apiman.gateway.engine.beans.Api, io.apiman.gateway.engine.async.IAsyncResultHandler) */ @Override public void publishApi(final Api api, final IAsyncResultHandler<Void> handler) { try { String id = getApiId(api); Index index = new Index.Builder(api).refresh(false) .index(getIndexName()).setParameter(Parameters.OP_TYPE, "index") //$NON-NLS-1$ .type("api").id(id).build(); //$NON-NLS-1$ JestResult result = getClient().execute(index); if (!result.isSucceeded()) { throw new IOException(result.getErrorMessage()); } else { handler.handle(AsyncResultImpl.create((Void) null)); } } catch (Exception e) { handler.handle(AsyncResultImpl.create( new PublishingException(Messages.i18n.format("ESRegistry.ErrorPublishingApi"), e), //$NON-NLS-1$ Void.class)); } }
/** * Indexes an entity. * @param type * @param id * @param sourceEntity * @param refresh true if the operation should wait for a refresh before it returns * @throws StorageException */ @SuppressWarnings("nls") private void indexEntity(String type, String id, XContentBuilder sourceEntity, boolean refresh) throws StorageException { try { String json = sourceEntity.string(); JestResult response = esClient.execute(new Index.Builder(json).refresh(refresh).index(getIndexName()) .setParameter(Parameters.OP_TYPE, "create").type(type).id(id).build()); if (!response.isSucceeded()) { throw new StorageException("Failed to index document " + id + " of type " + type + ": " + response.getErrorMessage()); } } catch (StorageException e) { throw e; } catch (Exception e) { throw new StorageException(e); } }
/** * @see io.apiman.gateway.engine.IRegistry#publishApi(io.apiman.gateway.engine.beans.Api, io.apiman.gateway.engine.async.IAsyncResultHandler) */ @Override public void publishApi(final Api api, final IAsyncResultHandler<Void> handler) { try { String id = getApiId(api); Index index = new Index.Builder(api).refresh(false) .index(getIndexName()).setParameter(Parameters.OP_TYPE, "index") //$NON-NLS-1$ .type("api").id(id).build(); //$NON-NLS-1$ JestResult result = getClient().execute(index); if (!result.isSucceeded()) { throw new IOException(result.getErrorMessage()); } else { handler.handle(AsyncResultImpl.create((Void) null)); } } catch (Exception e) { handler.handle(AsyncResultImpl.create( new PublishingException(Messages.i18n.format("ESRegistry.ErrorPublishingApi"), e), //$NON-NLS-1$ Void.class)); } }
/** * 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); } }
/** * 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); } }