org.elasticsearch.action.admin.indices.refresh.RefreshRequestBuilder Java Examples

The following examples show how to use org.elasticsearch.action.admin.indices.refresh.RefreshRequestBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ObjectIndexRefresh.java    From sfs with Apache License 2.0 6 votes vote down vote up
@Override
public Observable<PersistentContainer> call(PersistentContainer persistentContainer) {
    Elasticsearch elasticsearch = vertxContext.verticle().elasticsearch();

    String objectIndexName = elasticsearch.objectIndex(persistentContainer.getName());

    return aVoid()
            .flatMap(names -> {
                RefreshRequestBuilder request =
                        elasticsearch
                                .get()
                                .admin()
                                .indices()
                                .prepareRefresh(objectIndexName);
                return elasticsearch.execute(vertxContext, request, elasticsearch.getDefaultAdminTimeout())
                        .map(refreshResponseOptional -> persistentContainer);
            });
}
 
Example #2
Source File: IndexRefresh.java    From sfs with Apache License 2.0 6 votes vote down vote up
@Override
public Observable<Void> call(Void aVoid) {
    Elasticsearch elasticsearch = vertxContext.verticle().elasticsearch();
    return aVoid()
            .flatMap(new ListSfsIndexes(vertxContext))
            .flatMap(name -> {
                RefreshRequestBuilder request =
                        elasticsearch
                                .get()
                                .admin()
                                .indices()
                                .prepareRefresh(name);
                return elasticsearch.execute(vertxContext, request, elasticsearch.getDefaultAdminTimeout())
                        .map(refreshResponseOptional -> null);
            })
            .count()
            .map(new ToVoid<>());
}
 
Example #3
Source File: PluginClient.java    From openshift-elasticsearch-plugin with Apache License 2.0 5 votes vote down vote up
public RefreshResponse refreshIndices(String... indices) {
    return execute(new Callable<RefreshResponse>() {
        @Override
        public RefreshResponse call() throws Exception {
            RefreshRequestBuilder builder = client.admin().indices().prepareRefresh(indices);
            RefreshResponse response = builder.get();
            LOGGER.debug("Refreshed '{}' successfully on {} of {} shards", indices, response.getSuccessfulShards(),
                    response.getTotalShards());
            return response;
        }
    });
}
 
Example #4
Source File: AnalyticsServiceElasticsearch.java    From hawkular-apm with Apache License 2.0 5 votes vote down vote up
private static boolean refresh(String index) {
    try {
        AdminClient adminClient = client.getClient().admin();
        RefreshRequestBuilder refreshRequestBuilder = adminClient.indices().prepareRefresh(index);
        adminClient.indices().refresh(refreshRequestBuilder.request()).actionGet();
        return true;
    } catch (IndexMissingException t) {
        // Ignore, as means that no traces have
        // been stored yet
        if (msgLog.isTraceEnabled()) {
            msgLog.tracef("Index [%s] not found, unable to proceed.", index);
        }
        return false;
    }
}
 
Example #5
Source File: ElasticsearchClusterRunner.java    From elasticsearch-cluster-runner with Apache License 2.0 5 votes vote down vote up
public RefreshResponse refresh(final BuilderCallback<RefreshRequestBuilder> builder) {
    waitForRelocation();
    final RefreshResponse actionGet = builder.apply(client().admin().indices().prepareRefresh()).execute().actionGet();
    final ShardOperationFailedException[] shardFailures = actionGet.getShardFailures();
    if (shardFailures != null && shardFailures.length != 0) {
        final StringBuilder buf = new StringBuilder(100);
        for (final ShardOperationFailedException shardFailure : shardFailures) {
            buf.append(shardFailure.toString()).append('\n');
        }
        onFailure(buf.toString(), actionGet);
    }
    return actionGet;
}
 
Example #6
Source File: AbstractClient.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public RefreshRequestBuilder prepareRefresh(String... indices) {
    return new RefreshRequestBuilder(this, RefreshAction.INSTANCE).setIndices(indices);
}
 
Example #7
Source File: ElasticsearchClient.java    From hawkular-apm with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public void initTenant(String tenantId) throws StoreException {
    String index = getIndex(tenantId);

    if (!knownIndices.contains(index)) {
        synchronized (knownIndices) {
            if (!knownIndices.contains(index)) {
                if (log.isLoggable(Level.FINE)) {
                    log.fine("Initialise mappings for tenantId = " + tenantId);
                }

                InputStream s = Thread.currentThread().getContextClassLoader()
                        .getResourceAsStream(HAWKULAR_APM_MAPPING_JSON);
                if (s == null) {
                    s = ElasticsearchClient.class.getResourceAsStream("/" + HAWKULAR_APM_MAPPING_JSON);
                }

                if (s != null) {
                    try {
                        String jsonDefaultUserIndex = IOUtils.toString(s);
                        if (log.isLoggable(Level.FINEST)) {
                            log.finest("Mapping [" + jsonDefaultUserIndex + "]");
                        }

                        Map<String, Object> dataMap = XContentFactory.xContent(jsonDefaultUserIndex)
                                .createParser(jsonDefaultUserIndex).mapAndClose();

                        if (createIndex(index, (Map<String, Object>) dataMap.get(SETTINGS))) {
                            if (log.isLoggable(Level.FINEST)) {
                                log.finest("Index '" + index + "' created");
                            }
                            // refresh index
                            RefreshRequestBuilder refreshRequestBuilder = getClient().admin().indices()
                                    .prepareRefresh(index);
                            getClient().admin().indices().refresh(refreshRequestBuilder.request())
                            .actionGet();
                        } else if (log.isLoggable(Level.FINEST)) {
                            log.finest("Index '" + index + "' already exists. Doing nothing.");
                        }

                        // Apply mapping in case changes have occurred - however will only be done
                        // once per server session, for a particular index (i.e. tenant)
                        prepareMapping(index, (Map<String, Object>) dataMap.get(MAPPINGS));

                        knownIndices.add(index);
                    } catch (IOException ioe) {
                        throw new StoreException(ioe);
                    }
                } else {
                    log.warning("Could not locate '" + HAWKULAR_APM_MAPPING_JSON
                            + "' index mapping file. Mapping file required to use elasticsearch");
                }
            }
        }
    }
}
 
Example #8
Source File: ConfigurationServiceElasticsearch.java    From hawkular-apm with Apache License 2.0 4 votes vote down vote up
@Override
public CollectorConfiguration getCollector(String tenantId, String type, String host, String server) {
    CollectorConfiguration config = ConfigurationLoader.getConfiguration(type);

    try {
        String index = client.getIndex(tenantId);

        RefreshRequestBuilder refreshRequestBuilder =
                client.getClient().admin().indices().prepareRefresh(index);
        client.getClient().admin().indices().refresh(refreshRequestBuilder.request()).actionGet();

        // Only retrieve valid configurations
        SearchResponse response = client.getClient().prepareSearch(index)
                .setTypes(TXN_CONFIG_TYPE)
                .setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
                .setTimeout(TimeValue.timeValueMillis(timeout))
                .setSize(maxResponseSize)
                .setQuery(QueryBuilders.matchAllQuery()).execute().actionGet();
        if (response.isTimedOut()) {
            msgLog.warnQueryTimedOut();
        }

        for (SearchHit searchHitFields : response.getHits()) {
            try {
                TransactionConfig btc = mapper.readValue(searchHitFields.getSourceAsString(),
                        TransactionConfig.class);
                if (!btc.isDeleted()) {
                    config.getTransactions().put(searchHitFields.getId(), btc);
                }
            } catch (Exception e) {
                msgLog.errorFailedToParse(e);
            }
        }
    } catch (org.elasticsearch.indices.IndexMissingException t) {
        // Ignore, as means that no transaction configurations have
        // been stored yet
        if (msgLog.isTraceEnabled()) {
            msgLog.tracef("No index found, so unable to retrieve transaction configs");
        }
    }

    return config;
}
 
Example #9
Source File: ConfigurationServiceElasticsearch.java    From hawkular-apm with Apache License 2.0 4 votes vote down vote up
@Override
public TransactionConfig getTransaction(String tenantId, String name) {
    TransactionConfig ret = null;

    if (msgLog.isTraceEnabled()) {
        msgLog.tracef("Get transaction config with name[%s]", name);
    }

    try {
        String index = client.getIndex(tenantId);

        RefreshRequestBuilder refreshRequestBuilder =
                client.getClient().admin().indices().prepareRefresh(index);
        client.getClient().admin().indices().refresh(refreshRequestBuilder.request()).actionGet();

        // First check if an invalid config exists
        GetResponse response = client.getClient().prepareGet(
                index, TXN_CONFIG_INVALID_TYPE, name).setRouting(name)
                .execute()
                .actionGet();

        if (response.isSourceEmpty()) {
            // Retrieve the valid configuration
            response = client.getClient().prepareGet(
                    index, TXN_CONFIG_TYPE, name).setRouting(name)
                    .execute()
                    .actionGet();
        }

        if (!response.isSourceEmpty()) {
            try {
                ret = mapper.readValue(response.getSourceAsString(), TransactionConfig.class);

                // Check if config was deleted
                if (ret.isDeleted()) {
                    ret = null;
                }
            } catch (Exception e) {
                msgLog.errorFailedToParse(e);
            }
        }

    } catch (org.elasticsearch.indices.IndexMissingException t) {
        // Ignore, as means that no transaction configurations have
        // been stored yet
        if (msgLog.isTraceEnabled()) {
            msgLog.tracef("No index found, so unable to retrieve transaction config [%s]", name);
        }
    }

    if (msgLog.isTraceEnabled()) {
        msgLog.tracef("Get transaction config with name[%s] is: %s", name, ret);
    }

    return ret;
}
 
Example #10
Source File: ConfigurationServiceElasticsearch.java    From hawkular-apm with Apache License 2.0 4 votes vote down vote up
@Override
public Map<String, TransactionConfig> getTransactions(String tenantId, long updated) {
    Map<String, TransactionConfig> ret = new HashMap<String, TransactionConfig>();
    String index = client.getIndex(tenantId);

    try {
        RefreshRequestBuilder refreshRequestBuilder =
                client.getClient().admin().indices().prepareRefresh(index);
        client.getClient().admin().indices().refresh(refreshRequestBuilder.request()).actionGet();

        // Should only obtain valid transactions
        SearchResponse response = client.getClient().prepareSearch(index)
                .setTypes(TXN_CONFIG_TYPE)
                .setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
                .setTimeout(TimeValue.timeValueMillis(timeout))
                .setSize(maxResponseSize)
                .setQuery(QueryBuilders.matchAllQuery()).execute().actionGet();
        if (response.isTimedOut()) {
            msgLog.warnQueryTimedOut();
        }

        for (SearchHit searchHitFields : response.getHits()) {
            try {
                TransactionConfig btxn = mapper.readValue(searchHitFields.getSourceAsString(),
                        TransactionConfig.class);
                if ((updated == 0 && !btxn.isDeleted()) || (updated > 0 && btxn.getLastUpdated() > updated)) {
                    ret.put(searchHitFields.getId(), btxn);
                }
            } catch (Exception e) {
                msgLog.errorFailedToParse(e);
            }
        }
    } catch (org.elasticsearch.indices.IndexMissingException t) {
        // Ignore, as means that no transaction configurations have
        // been stored yet
        if (msgLog.isTraceEnabled()) {
            msgLog.tracef("No index found, so unable to retrieve transaction names");
        }
    }

    return ret;
}
 
Example #11
Source File: AbstractClient.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public RefreshRequestBuilder prepareRefresh(String... indices) {
    return new RefreshRequestBuilder(this, RefreshAction.INSTANCE).setIndices(indices);
}
 
Example #12
Source File: IndicesAdminClient.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Explicitly refresh one or more indices (making the content indexed since the last refresh searchable).
 */
RefreshRequestBuilder prepareRefresh(String... indices);
 
Example #13
Source File: IndicesAdminClient.java    From crate with Apache License 2.0 2 votes vote down vote up
/**
 * Explicitly refresh one or more indices (making the content indexed since the last refresh searchable).
 */
RefreshRequestBuilder prepareRefresh(String... indices);