org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest Java Examples
The following examples show how to use
org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest.
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: TransportNodePrometheusMetricsAction.java From elasticsearch-prometheus-exporter with Apache License 2.0 | 6 votes |
private AsyncAction(ActionListener<NodePrometheusMetricsResponse> listener) { this.listener = listener; // Note: when using ClusterHealthRequest in Java, it pulls data at the shards level, according to ES source // code comment this is "so it is backward compatible with the transport client behaviour". // hence we are explicit about ClusterHealthRequest level and do not rely on defaults. // https://www.elastic.co/guide/en/elasticsearch/reference/6.4/cluster-health.html#request-params this.healthRequest = Requests.clusterHealthRequest().local(true); this.healthRequest.level(ClusterHealthRequest.Level.SHARDS); this.nodesStatsRequest = Requests.nodesStatsRequest("_local").clear().all(); // Indices stats request is not "node-specific", it does not support any "_local" notion // it is broad-casted to all cluster nodes. this.indicesStatsRequest = isPrometheusIndices ? new IndicesStatsRequest() : null; // Cluster settings are get via ClusterStateRequest (see elasticsearch RestClusterGetSettingsAction for details) // We prefer to send it to master node (hence local=false; it should be set by default but we want to be sure). this.clusterStateRequest = isPrometheusClusterSettings ? Requests.clusterStateRequest() .clear().metadata(true).local(false) : null; }
Example #2
Source File: RestShardsAction.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public void doRequest(final RestRequest request, final RestChannel channel, final Client client) { final String[] indices = Strings.splitStringByCommaToArray(request.param("index")); final ClusterStateRequest clusterStateRequest = new ClusterStateRequest(); clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local())); clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout())); clusterStateRequest.clear().nodes(true).metaData(true).routingTable(true).indices(indices); client.admin().cluster().state(clusterStateRequest, new RestActionListener<ClusterStateResponse>(channel) { @Override public void processResponse(final ClusterStateResponse clusterStateResponse) { IndicesStatsRequest indicesStatsRequest = new IndicesStatsRequest(indices); indicesStatsRequest.all(); client.admin().indices().stats(indicesStatsRequest, new RestResponseListener<IndicesStatsResponse>(channel) { @Override public RestResponse buildResponse(IndicesStatsResponse indicesStatsResponse) throws Exception { return RestTable.buildResponse(buildTable(request, clusterStateResponse, indicesStatsResponse), channel); } }); } }); }
Example #3
Source File: ElasticSearchComponent.java From metron with Apache License 2.0 | 5 votes |
public boolean hasIndex(String indexName) { Set<String> indices = getClient().admin() .indices() .stats(new IndicesStatsRequest()) .actionGet() .getIndices() .keySet(); return indices.contains(indexName); }
Example #4
Source File: InternalClusterInfoService.java From crate with Apache License 2.0 | 5 votes |
/** * Retrieve the latest indices stats, calling the listener when complete * @return a latch that can be used to wait for the indices stats to complete if desired */ private CountDownLatch updateIndicesStats(final ActionListener<IndicesStatsResponse> listener) { final CountDownLatch latch = new CountDownLatch(1); final IndicesStatsRequest indicesStatsRequest = new IndicesStatsRequest(); indicesStatsRequest.clear(); indicesStatsRequest.store(true); client.admin().indices().stats(indicesStatsRequest, new LatchedActionListener<>(listener, latch)); return latch; }
Example #5
Source File: StatsRequestBuilder.java From elasticshell with Apache License 2.0 | 5 votes |
@Override protected XContentBuilder toXContent(IndicesStatsRequest request, IndicesStatsResponse response, XContentBuilder builder) throws IOException { builder.startObject(); builder.field(Fields.OK, true); buildBroadcastShardsHeader(builder, response); response.toXContent(builder, ToXContent.EMPTY_PARAMS); builder.endObject(); return builder; }
Example #6
Source File: IndexUtils.java From anomaly-detection with Apache License 2.0 | 5 votes |
/** * Gets the number of documents in an index. * * @deprecated * * @param indexName Name of the index * @return The number of documents in an index. 0 is returned if the index does not exist. -1 is returned if the * request fails. */ @Deprecated public Long getNumberOfDocumentsInIndex(String indexName) { if (!clusterService.state().getRoutingTable().hasIndex(indexName)) { return 0L; } IndicesStatsRequest indicesStatsRequest = new IndicesStatsRequest(); Optional<IndicesStatsResponse> response = clientUtil.timedRequest(indicesStatsRequest, logger, client.admin().indices()::stats); return response.map(r -> r.getIndex(indexName).getPrimaries().docs.getCount()).orElse(-1L); }
Example #7
Source File: InternalClusterInfoService.java From Elasticsearch with Apache License 2.0 | 5 votes |
/** * Retrieve the latest indices stats, calling the listener when complete * @return a latch that can be used to wait for the indices stats to complete if desired */ protected CountDownLatch updateIndicesStats(final ActionListener<IndicesStatsResponse> listener) { final CountDownLatch latch = new CountDownLatch(1); final IndicesStatsRequest indicesStatsRequest = new IndicesStatsRequest(); indicesStatsRequest.clear(); indicesStatsRequest.store(true); transportIndicesStatsAction.execute(indicesStatsRequest, new LatchedActionListener<>(listener, latch)); return latch; }
Example #8
Source File: RestIndicesStatsAction.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { IndicesStatsRequest indicesStatsRequest = new IndicesStatsRequest(); indicesStatsRequest.indicesOptions(IndicesOptions.fromRequest(request, indicesStatsRequest.indicesOptions())); indicesStatsRequest.indices(Strings.splitStringByCommaToArray(request.param("index"))); indicesStatsRequest.types(Strings.splitStringByCommaToArray(request.param("types"))); Set<String> metrics = Strings.splitStringByCommaToSet(request.param("metric", "_all")); // short cut, if no metrics have been specified in URI if (metrics.size() == 1 && metrics.contains("_all")) { indicesStatsRequest.all(); } else { indicesStatsRequest.clear(); indicesStatsRequest.docs(metrics.contains("docs")); indicesStatsRequest.store(metrics.contains("store")); indicesStatsRequest.indexing(metrics.contains("indexing")); indicesStatsRequest.search(metrics.contains("search")); indicesStatsRequest.get(metrics.contains("get")); indicesStatsRequest.merge(metrics.contains("merge")); indicesStatsRequest.refresh(metrics.contains("refresh")); indicesStatsRequest.flush(metrics.contains("flush")); indicesStatsRequest.warmer(metrics.contains("warmer")); indicesStatsRequest.queryCache(metrics.contains("query_cache")); indicesStatsRequest.percolate(metrics.contains("percolate")); indicesStatsRequest.segments(metrics.contains("segments")); indicesStatsRequest.fieldData(metrics.contains("fielddata")); indicesStatsRequest.completion(metrics.contains("completion")); indicesStatsRequest.suggest(metrics.contains("suggest")); indicesStatsRequest.requestCache(metrics.contains("request_cache")); indicesStatsRequest.recovery(metrics.contains("recovery")); indicesStatsRequest.translog(metrics.contains("translog")); } if (request.hasParam("groups")) { indicesStatsRequest.groups(Strings.splitStringByCommaToArray(request.param("groups"))); } if (request.hasParam("types")) { indicesStatsRequest.types(Strings.splitStringByCommaToArray(request.param("types"))); } if (indicesStatsRequest.completion() && (request.hasParam("fields") || request.hasParam("completion_fields"))) { indicesStatsRequest.completionFields(request.paramAsStringArray("completion_fields", request.paramAsStringArray("fields", Strings.EMPTY_ARRAY))); } if (indicesStatsRequest.fieldData() && (request.hasParam("fields") || request.hasParam("fielddata_fields"))) { indicesStatsRequest.fieldDataFields(request.paramAsStringArray("fielddata_fields", request.paramAsStringArray("fields", Strings.EMPTY_ARRAY))); } client.admin().indices().stats(indicesStatsRequest, new RestBuilderListener<IndicesStatsResponse>(channel) { @Override public RestResponse buildResponse(IndicesStatsResponse response, XContentBuilder builder) throws Exception { builder.startObject(); buildBroadcastShardsHeader(builder, request, response); response.toXContent(builder, request); builder.endObject(); return new BytesRestResponse(OK, builder); } }); }
Example #9
Source File: RequestUtils.java From ranger with Apache License 2.0 | 4 votes |
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) { indexs.add(((PutMappingRequest) request).getConcreteIndex().getName()); return indexs; } 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; } } // No matched request type to find specific index , set default value * indexs.add("*"); return indexs; }
Example #10
Source File: StatsRequestBuilder.java From elasticshell with Apache License 2.0 | 4 votes |
public StatsRequestBuilder(Client client, JsonToString<JsonInput> jsonToString, StringToJson<JsonOutput> stringToJson) { super(client, new IndicesStatsRequest(), jsonToString, stringToJson); }
Example #11
Source File: StatsRequestBuilder.java From elasticshell with Apache License 2.0 | 4 votes |
@Override protected ActionFuture<IndicesStatsResponse> doExecute(IndicesStatsRequest request) { return client.admin().indices().stats(request); }
Example #12
Source File: AbstractClient.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override public void stats(final IndicesStatsRequest request, final ActionListener<IndicesStatsResponse> listener) { execute(IndicesStatsAction.INSTANCE, request, listener); }
Example #13
Source File: AbstractClient.java From crate with Apache License 2.0 | 4 votes |
@Override public ActionFuture<IndicesStatsResponse> stats(final IndicesStatsRequest request) { return execute(IndicesStatsAction.INSTANCE, request); }
Example #14
Source File: AbstractClient.java From crate with Apache License 2.0 | 4 votes |
@Override public void stats(final IndicesStatsRequest request, final ActionListener<IndicesStatsResponse> listener) { execute(IndicesStatsAction.INSTANCE, request, listener); }
Example #15
Source File: AbstractClient.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override public ActionFuture<IndicesStatsResponse> stats(final IndicesStatsRequest request) { return execute(IndicesStatsAction.INSTANCE, request); }
Example #16
Source File: IndicesAdminClient.java From Elasticsearch with Apache License 2.0 | 2 votes |
/** * Indices stats. */ void stats(IndicesStatsRequest request, ActionListener<IndicesStatsResponse> listener);
Example #17
Source File: IndicesAdminClient.java From Elasticsearch with Apache License 2.0 | 2 votes |
/** * Indices stats. */ ActionFuture<IndicesStatsResponse> stats(IndicesStatsRequest request);
Example #18
Source File: IndicesAdminClient.java From crate with Apache License 2.0 | 2 votes |
/** * Indices stats. */ ActionFuture<IndicesStatsResponse> stats(IndicesStatsRequest request);
Example #19
Source File: IndicesAdminClient.java From crate with Apache License 2.0 | 2 votes |
/** * Indices stats. */ void stats(IndicesStatsRequest request, ActionListener<IndicesStatsResponse> listener);