Search in sources :

Example 11 with GetSettingsRequest

use of org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest in project open-commerce-search by CommerceExperts.

the class ElasticsearchSuggestDataProvider method getLastDataModTime.

@Override
public long getLastDataModTime(String indexName) throws IOException {
    long lastModTime = -1;
    try {
        GetSettingsResponse settingsResponse = client.indices().getSettings(new GetSettingsRequest().indices(indexName), RequestOptions.DEFAULT);
        String creationDateTs = settingsResponse.getSetting(settingsResponse.getIndexToSettings().keysIt().next(), "index.creation_date");
        if (creationDateTs != null) {
            lastModTime = Long.parseLong(creationDateTs);
        }
    } catch (IOException e) {
        log.error("failed to fetch index creation timestamp for index {} because of IOException: {}", indexName, e.getMessage());
    }
    return lastModTime;
}
Also used : GetSettingsRequest(org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest) GetSettingsResponse(org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse) IOException(java.io.IOException)

Example 12 with GetSettingsRequest

use of org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest in project bubble-fireworks by fxbin.

the class IndexOperations method getSettings.

/**
 * getSettings
 *
 * @since 2020/5/27 15:49
 * @param indexName index name
 * @param includeDefaults is clude
 * @return java.util.Map<java.lang.String,java.lang.Object>
 */
public Map<String, Object> getSettings(String indexName, boolean includeDefaults) {
    GetSettingsRequest request = getSettingsRequest().indices(indexName).includeDefaults(includeDefaults);
    GetSettingsResponse response = execute(client -> client.indices().getSettings(request, COMMON_OPTIONS));
    return convertSettingsResponseToMap(response, indexName);
}
Also used : GetSettingsRequest(org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest) GetSettingsResponse(org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse)

Example 13 with GetSettingsRequest

use of org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest in project ranger by apache.

the class RequestUtils method getIndexFromRequest.

// To support all kinds of request in elasticsearch
public static <Request extends ActionRequest> List<String> getIndexFromRequest(Request request) {
    List<String> indexs = new ArrayList<>();
    if (request instanceof SingleShardRequest) {
        indexs.add(((SingleShardRequest<?>) request).index());
        return indexs;
    }
    if (request instanceof ReplicationRequest) {
        indexs.add(((ReplicationRequest<?>) request).index());
        return indexs;
    }
    if (request instanceof InstanceShardOperationRequest) {
        indexs.add(((InstanceShardOperationRequest<?>) request).index());
        return indexs;
    }
    if (request instanceof CreateIndexRequest) {
        indexs.add(((CreateIndexRequest) request).index());
        return indexs;
    }
    if (request instanceof PutMappingRequest) {
        if (((PutMappingRequest) request).getConcreteIndex() != null) {
            indexs.add(((PutMappingRequest) request).getConcreteIndex().getName());
            return indexs;
        } else {
            return Arrays.asList(((PutMappingRequest) request).indices());
        }
    }
    if (request instanceof SearchRequest) {
        return Arrays.asList(((SearchRequest) request).indices());
    }
    if (request instanceof IndicesStatsRequest) {
        return Arrays.asList(((IndicesStatsRequest) request).indices());
    }
    if (request instanceof OpenIndexRequest) {
        return Arrays.asList(((OpenIndexRequest) request).indices());
    }
    if (request instanceof DeleteIndexRequest) {
        return Arrays.asList(((DeleteIndexRequest) request).indices());
    }
    if (request instanceof BulkRequest) {
        @SuppressWarnings("rawtypes") List<DocWriteRequest<?>> requests = ((BulkRequest) request).requests();
        if (CollectionUtils.isNotEmpty(requests)) {
            for (DocWriteRequest<?> docWriteRequest : requests) {
                indexs.add(docWriteRequest.index());
            }
            return indexs;
        }
    }
    if (request instanceof MultiGetRequest) {
        List<Item> items = ((MultiGetRequest) request).getItems();
        if (CollectionUtils.isNotEmpty(items)) {
            for (Item item : items) {
                indexs.add(item.index());
            }
            return indexs;
        }
    }
    if (request instanceof GetMappingsRequest) {
        return Arrays.asList(((GetMappingsRequest) request).indices());
    }
    if (request instanceof GetSettingsRequest) {
        return Arrays.asList(((GetSettingsRequest) request).indices());
    }
    if (request instanceof IndicesExistsRequest) {
        return Arrays.asList(((IndicesExistsRequest) request).indices());
    }
    if (request instanceof GetAliasesRequest) {
        return Arrays.asList(((GetAliasesRequest) request).indices());
    }
    if (request instanceof GetIndexRequest) {
        return Arrays.asList(((GetIndexRequest) request).indices());
    }
    if (request instanceof GetFieldMappingsRequest) {
        return Arrays.asList(((GetFieldMappingsRequest) request).indices());
    }
    if (request instanceof TypesExistsRequest) {
        return Arrays.asList(((TypesExistsRequest) request).indices());
    }
    if (request instanceof ValidateQueryRequest) {
        return Arrays.asList(((ValidateQueryRequest) request).indices());
    }
    if (request instanceof RecoveryRequest) {
        return Arrays.asList(((RecoveryRequest) request).indices());
    }
    if (request instanceof IndicesSegmentsRequest) {
        return Arrays.asList(((IndicesSegmentsRequest) request).indices());
    }
    if (request instanceof IndicesShardStoresRequest) {
        return Arrays.asList(((IndicesShardStoresRequest) request).indices());
    }
    if (request instanceof UpgradeStatusRequest) {
        return Arrays.asList(((UpgradeStatusRequest) request).indices());
    }
    if (request instanceof ClusterSearchShardsRequest) {
        return Arrays.asList(((ClusterSearchShardsRequest) request).indices());
    }
    if (request instanceof IndicesAliasesRequest) {
        List<IndicesAliasesRequest.AliasActions> aliasActions = ((IndicesAliasesRequest) request).getAliasActions();
        if (CollectionUtils.isNotEmpty(aliasActions)) {
            for (IndicesAliasesRequest.AliasActions action : aliasActions) {
                indexs.addAll(Arrays.asList(action.indices()));
            }
            return indexs;
        }
    }
    if (request instanceof ClearIndicesCacheRequest) {
        return Arrays.asList(((ClearIndicesCacheRequest) request).indices());
    }
    if (request instanceof CloseIndexRequest) {
        return Arrays.asList(((CloseIndexRequest) request).indices());
    }
    if (request instanceof FlushRequest) {
        return Arrays.asList(((FlushRequest) request).indices());
    }
    if (request instanceof SyncedFlushRequest) {
        return Arrays.asList(((SyncedFlushRequest) request).indices());
    }
    if (request instanceof ForceMergeRequest) {
        return Arrays.asList(((ForceMergeRequest) request).indices());
    }
    if (request instanceof RefreshRequest) {
        return Arrays.asList(((RefreshRequest) request).indices());
    }
    if (request instanceof RolloverRequest) {
        return Arrays.asList(((RolloverRequest) request).indices());
    }
    if (request instanceof UpdateSettingsRequest) {
        return Arrays.asList(((UpdateSettingsRequest) request).indices());
    }
    if (request instanceof ResizeRequest) {
        return Arrays.asList(((ResizeRequest) request).indices());
    }
    if (request instanceof DeleteIndexTemplateRequest) {
        indexs.add(((DeleteIndexTemplateRequest) request).name());
        return indexs;
    }
    if (request instanceof GetIndexTemplatesRequest) {
        return Arrays.asList(((GetIndexTemplatesRequest) request).names());
    }
    if (request instanceof PutIndexTemplateRequest) {
        indexs.add(((PutIndexTemplateRequest) request).name());
        return indexs;
    }
    if (request instanceof UpgradeRequest) {
        return Arrays.asList(((UpgradeRequest) request).indices());
    }
    if (request instanceof FieldCapabilitiesRequest) {
        return Arrays.asList(((FieldCapabilitiesRequest) request).indices());
    }
    if (request instanceof MultiSearchRequest) {
        List<SearchRequest> searchRequests = ((MultiSearchRequest) request).requests();
        if (CollectionUtils.isNotEmpty(searchRequests)) {
            for (SearchRequest singleRequest : searchRequests) {
                indexs.addAll(Arrays.asList(singleRequest.indices()));
            }
            return indexs;
        }
    }
    if (request instanceof MultiTermVectorsRequest) {
        List<TermVectorsRequest> termVectorsRequests = ((MultiTermVectorsRequest) request).getRequests();
        if (CollectionUtils.isNotEmpty(termVectorsRequests)) {
            for (TermVectorsRequest singleRequest : termVectorsRequests) {
                indexs.addAll(Arrays.asList(singleRequest.indices()));
            }
            return indexs;
        }
    }
    if (request instanceof UpdateByQueryRequest) {
        return Arrays.asList(((UpdateByQueryRequest) request).indices());
    }
    if (request instanceof DeleteByQueryRequest) {
        return Arrays.asList(((DeleteByQueryRequest) request).indices());
    }
    if (request instanceof ReindexRequest) {
        indexs.addAll(Arrays.asList(((ReindexRequest) request).getSearchRequest().indices()));
        indexs.addAll(Arrays.asList(((ReindexRequest) request).getDestination().indices()));
        return indexs;
    }
    // ClearScrollRequest does not carry any index, so return empty List
    if (request instanceof ClearScrollRequest) {
        return indexs;
    }
    // No matched request type to find specific index , set default value *
    indexs.add("*");
    return indexs;
}
Also used : ForceMergeRequest(org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest) IndicesShardStoresRequest(org.elasticsearch.action.admin.indices.shards.IndicesShardStoresRequest) TypesExistsRequest(org.elasticsearch.action.admin.indices.exists.types.TypesExistsRequest) ClearIndicesCacheRequest(org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest) ArrayList(java.util.ArrayList) DeleteIndexRequest(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest) ReplicationRequest(org.elasticsearch.action.support.replication.ReplicationRequest) DeleteIndexTemplateRequest(org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest) SyncedFlushRequest(org.elasticsearch.action.admin.indices.flush.SyncedFlushRequest) InstanceShardOperationRequest(org.elasticsearch.action.support.single.instance.InstanceShardOperationRequest) MultiGetRequest(org.elasticsearch.action.get.MultiGetRequest) Item(org.elasticsearch.action.get.MultiGetRequest.Item) ReindexRequest(org.elasticsearch.index.reindex.ReindexRequest) SingleShardRequest(org.elasticsearch.action.support.single.shard.SingleShardRequest) RolloverRequest(org.elasticsearch.action.admin.indices.rollover.RolloverRequest) GetFieldMappingsRequest(org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsRequest) IndicesSegmentsRequest(org.elasticsearch.action.admin.indices.segments.IndicesSegmentsRequest) ClusterSearchShardsRequest(org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsRequest) IndicesAliasesRequest(org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest) DocWriteRequest(org.elasticsearch.action.DocWriteRequest) RefreshRequest(org.elasticsearch.action.admin.indices.refresh.RefreshRequest) TermVectorsRequest(org.elasticsearch.action.termvectors.TermVectorsRequest) MultiTermVectorsRequest(org.elasticsearch.action.termvectors.MultiTermVectorsRequest) SearchRequest(org.elasticsearch.action.search.SearchRequest) MultiSearchRequest(org.elasticsearch.action.search.MultiSearchRequest) PutMappingRequest(org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest) UpdateSettingsRequest(org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest) UpgradeRequest(org.elasticsearch.action.admin.indices.upgrade.post.UpgradeRequest) GetIndexTemplatesRequest(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesRequest) PutIndexTemplateRequest(org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest) RecoveryRequest(org.elasticsearch.action.admin.indices.recovery.RecoveryRequest) SyncedFlushRequest(org.elasticsearch.action.admin.indices.flush.SyncedFlushRequest) FlushRequest(org.elasticsearch.action.admin.indices.flush.FlushRequest) UpgradeStatusRequest(org.elasticsearch.action.admin.indices.upgrade.get.UpgradeStatusRequest) GetIndexRequest(org.elasticsearch.action.admin.indices.get.GetIndexRequest) GetAliasesRequest(org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest) ClearScrollRequest(org.elasticsearch.action.search.ClearScrollRequest) OpenIndexRequest(org.elasticsearch.action.admin.indices.open.OpenIndexRequest) DeleteByQueryRequest(org.elasticsearch.index.reindex.DeleteByQueryRequest) ValidateQueryRequest(org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest) GetMappingsRequest(org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest) UpdateByQueryRequest(org.elasticsearch.index.reindex.UpdateByQueryRequest) GetSettingsRequest(org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest) CloseIndexRequest(org.elasticsearch.action.admin.indices.close.CloseIndexRequest) BulkRequest(org.elasticsearch.action.bulk.BulkRequest) MultiTermVectorsRequest(org.elasticsearch.action.termvectors.MultiTermVectorsRequest) MultiSearchRequest(org.elasticsearch.action.search.MultiSearchRequest) FieldCapabilitiesRequest(org.elasticsearch.action.fieldcaps.FieldCapabilitiesRequest) CreateIndexRequest(org.elasticsearch.action.admin.indices.create.CreateIndexRequest) IndicesExistsRequest(org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest) ResizeRequest(org.elasticsearch.action.admin.indices.shrink.ResizeRequest) IndicesStatsRequest(org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest)

Example 14 with GetSettingsRequest

use of org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest in project herd by FINRAOS.

the class IndexFunctionsDaoImpl method getIndexSettings.

@Override
public Settings getIndexSettings(final String indexName) {
    LOGGER.info("Get the Elasticsearch index settings, indexName={}.", indexName);
    // Build the get settings request.
    GetSettingsRequest request = new GetSettingsRequest().indices(indexName);
    // Create a get settings reponse object.
    GetSettingsResponse getSettingsResponse;
    // Get the Elasticsearch REST high level client. The REST high level client is auto closeable, so use try with resources.
    try (final RestHighLevelClient restHighLevelClient = elasticsearchRestHighLevelClientFactory.getRestHighLevelClient()) {
        // Make the get settings request.
        getSettingsResponse = restHighLevelClient.indices().getSettings(request, RequestOptions.DEFAULT);
    } catch (final IOException ioException) {
        LOGGER.error("Caught IOException while attempting to use the ElasticsearchRestHighLevelClient.", ioException);
        throw new ElasticsearchRestClientException("Caught IOException while attempting to use the ElasticsearchRestHighLevelClient.", ioException);
    }
    return getSettingsResponse.getIndexToSettings().get(indexName);
}
Also used : GetSettingsRequest(org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest) GetSettingsResponse(org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient) IOException(java.io.IOException) ElasticsearchRestClientException(org.finra.herd.dao.exception.ElasticsearchRestClientException)

Example 15 with GetSettingsRequest

use of org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest in project LinkAgent by shulieTech.

the class GetSettingsRequestIndexRename method reindex0.

@Override
public List<String> reindex0(Object target) {
    GetSettingsRequest req = (GetSettingsRequest) target;
    String[] indices = req.indices();
    if (ArrayUtils.isEmpty(indices)) {
        return Collections.EMPTY_LIST;
    }
    for (int i = 0, len = indices.length; i < len; i++) {
        /**
         * 如果索引在白名单中,则不需要走
         */
        if (GlobalConfig.getInstance().getSearchWhiteList().contains(indices[i])) {
            continue;
        }
        if (!Pradar.isClusterTestPrefix(indices[i])) {
            indices[i] = Pradar.addClusterTestPrefixLower(indices[i]);
        }
    }
    req.indices(indices);
    return Arrays.asList(indices);
}
Also used : GetSettingsRequest(org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest)

Aggregations

GetSettingsRequest (org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest)15 GetSettingsResponse (org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse)8 IOException (java.io.IOException)3 DeleteIndexRequest (org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)3 DocWriteRequest (org.elasticsearch.action.DocWriteRequest)2 IndicesAliasesRequest (org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest)2 GetAliasesRequest (org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest)2 CloseIndexRequest (org.elasticsearch.action.admin.indices.close.CloseIndexRequest)2 CreateIndexRequest (org.elasticsearch.action.admin.indices.create.CreateIndexRequest)2 FlushRequest (org.elasticsearch.action.admin.indices.flush.FlushRequest)2 GetIndexRequest (org.elasticsearch.action.admin.indices.get.GetIndexRequest)2 GetMappingsRequest (org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest)2 PutMappingRequest (org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest)2 OpenIndexRequest (org.elasticsearch.action.admin.indices.open.OpenIndexRequest)2 RefreshRequest (org.elasticsearch.action.admin.indices.refresh.RefreshRequest)2 DeleteIndexTemplateRequest (org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest)2 BulkRequest (org.elasticsearch.action.bulk.BulkRequest)2 FieldCapabilitiesRequest (org.elasticsearch.action.fieldcaps.FieldCapabilitiesRequest)2 MultiGetRequest (org.elasticsearch.action.get.MultiGetRequest)2 ObjectObjectCursor (com.carrotsearch.hppc.cursors.ObjectObjectCursor)1