Search in sources :

Example 1 with CatResult

use of io.searchbox.core.CatResult in project graylog2-server by Graylog2.

the class IndicesAdapterES6 method catIndices.

/**
 * Retrieve the response for the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-indices.html">cat indices</a> request from Elasticsearch.
 *
 * @param fields The fields to show, see <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-indices.html">cat indices API</a>.
 * @return A {@link JsonNode} with the result of the cat indices request.
 */
private JsonNode catIndices(Collection<String> indices, String... fields) {
    final String fieldNames = String.join(",", fields);
    final Cat request = new Cat.IndicesBuilder().addIndex(indices).setParameter("h", fieldNames).build();
    final CatResult response = JestUtils.execute(jestClient, request, () -> "Unable to read information for indices " + indices);
    return response.getJsonObject().path("result");
}
Also used : CatResult(io.searchbox.core.CatResult) Cat(io.searchbox.core.Cat)

Example 2 with CatResult

use of io.searchbox.core.CatResult in project graylog2-server by Graylog2.

the class IndicesAdapterES6 method indices.

@Override
public Set<String> indices(String indexWildcard, List<String> status, String indexSetId) {
    final Cat catRequest = new Cat.IndicesBuilder().addIndex(indexWildcard).setParameter("h", "index,status").build();
    final CatResult result = JestUtils.execute(jestClient, catRequest, () -> "Couldn't get index list for index set <" + indexSetId + ">");
    return StreamSupport.stream(result.getJsonObject().path("result").spliterator(), false).filter(cat -> status.isEmpty() || status.contains(cat.path("status").asText())).map(cat -> cat.path("index").asText()).collect(Collectors.toSet());
}
Also used : TermsAggregation(io.searchbox.core.search.aggregation.TermsAggregation) DateTimeZone(org.joda.time.DateTimeZone) Arrays(java.util.Arrays) PutTemplate(io.searchbox.indices.template.PutTemplate) LoggerFactory(org.slf4j.LoggerFactory) ModifyAliases(io.searchbox.indices.aliases.ModifyAliases) RequestConfig(org.apache.http.client.config.RequestConfig) TypeReferences(org.graylog2.jackson.TypeReferences) UpdateSettings(io.searchbox.indices.settings.UpdateSettings) FieldSortBuilder(org.graylog.shaded.elasticsearch6.org.elasticsearch.search.sort.FieldSortBuilder) MaxAggregation(io.searchbox.core.search.aggregation.MaxAggregation) IndicesAdapter(org.graylog2.indexer.indices.IndicesAdapter) HealthStatus(org.graylog2.indexer.indices.HealthStatus) JestUtils(org.graylog.storage.elasticsearch6.jest.JestUtils) Indices(org.graylog2.indexer.indices.Indices) Locale(java.util.Locale) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) IndexRangeStats(org.graylog2.indexer.searches.IndexRangeStats) Bulk(io.searchbox.core.Bulk) Cat(io.searchbox.core.Cat) IndexMapping(org.graylog2.indexer.IndexMapping) FilterAggregation(io.searchbox.core.search.aggregation.FilterAggregation) QueryBuilders(org.graylog.shaded.elasticsearch6.org.elasticsearch.index.query.QueryBuilders) SearchSourceBuilder.searchSource(org.graylog.shaded.elasticsearch6.org.elasticsearch.search.builder.SearchSourceBuilder.searchSource) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) Set(java.util.Set) Health(io.searchbox.cluster.Health) AddAliasMapping(io.searchbox.indices.aliases.AddAliasMapping) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) GetAliases(io.searchbox.indices.aliases.GetAliases) RemoveAliasMapping(io.searchbox.indices.aliases.RemoveAliasMapping) PutMapping(io.searchbox.indices.mapping.PutMapping) DeleteIndex(io.searchbox.indices.DeleteIndex) Stats(io.searchbox.indices.Stats) List(java.util.List) Parameters(io.searchbox.params.Parameters) OpenIndex(io.searchbox.indices.OpenIndex) AggregationBuilders(org.graylog.shaded.elasticsearch6.org.elasticsearch.search.aggregations.AggregationBuilders) IndexMoveResult(org.graylog2.indexer.indices.IndexMoveResult) Optional(java.util.Optional) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SearchSourceBuilder(org.graylog.shaded.elasticsearch6.org.elasticsearch.search.builder.SearchSourceBuilder) SearchResult(io.searchbox.core.SearchResult) FilterAggregationBuilder(org.graylog.shaded.elasticsearch6.org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder) HashMap(java.util.HashMap) ElasticsearchException(org.graylog2.indexer.ElasticsearchException) SearchType(io.searchbox.params.SearchType) Iterators(com.google.common.collect.Iterators) JestClient(io.searchbox.client.JestClient) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) SortBuilders(org.graylog.shaded.elasticsearch6.org.elasticsearch.search.sort.SortBuilders) ImmutableList(com.google.common.collect.ImmutableList) Flush(io.searchbox.indices.Flush) DeleteTemplate(io.searchbox.indices.template.DeleteTemplate) IndexStatistics(org.graylog2.indexer.indices.stats.IndexStatistics) Duration(com.github.joschi.jadconfig.util.Duration) StreamSupport(java.util.stream.StreamSupport) Nonnull(javax.annotation.Nonnull) GetSettings(io.searchbox.indices.settings.GetSettings) Logger(org.slf4j.Logger) MinAggregation(io.searchbox.core.search.aggregation.MinAggregation) Iterator(java.util.Iterator) IndexSettings(org.graylog2.indexer.indices.IndexSettings) IndexNotFoundException(org.graylog2.indexer.IndexNotFoundException) SearchScroll(io.searchbox.core.SearchScroll) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Search(io.searchbox.core.Search) AliasMapping(io.searchbox.indices.aliases.AliasMapping) DateTime(org.joda.time.DateTime) ForceMerge(io.searchbox.indices.ForceMerge) GetSingleAlias(org.graylog.storage.elasticsearch6.indices.GetSingleAlias) IOException(java.io.IOException) JestResult(io.searchbox.client.JestResult) Ints(com.google.common.primitives.Ints) CreateIndex(io.searchbox.indices.CreateIndex) BulkResult(io.searchbox.core.BulkResult) Consumer(java.util.function.Consumer) URLEncoder(java.net.URLEncoder) Collectors.toList(java.util.stream.Collectors.toList) CatResult(io.searchbox.core.CatResult) SerializationFeature(com.fasterxml.jackson.databind.SerializationFeature) CloseIndex(io.searchbox.indices.CloseIndex) GetTemplate(io.searchbox.indices.template.GetTemplate) Message(org.graylog2.plugin.Message) Collections(java.util.Collections) State(io.searchbox.cluster.State) CatResult(io.searchbox.core.CatResult) Cat(io.searchbox.core.Cat)

Example 3 with CatResult

use of io.searchbox.core.CatResult in project graylog2-server by Graylog2.

the class ClusterAdapterES6 method catNodes.

/**
 * Retrieve the response for the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-nodes.html">cat nodes</a> request from Elasticsearch.
 *
 * @param fields The fields to show, see <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-nodes.html">cat nodes API</a>.
 * @return A {@link JsonNode} with the result of the cat nodes request.
 */
private JsonNode catNodes(String... fields) {
    final String fieldNames = String.join(",", fields);
    final Cat request = new Cat.NodesBuilder().setParameter("h", fieldNames).setParameter("full_id", true).setParameter("format", "json").build();
    final CatResult response = JestUtils.execute(jestClient, request, () -> "Unable to read Elasticsearch node information");
    return response.getJsonObject().path("result");
}
Also used : CatResult(io.searchbox.core.CatResult) Cat(io.searchbox.core.Cat)

Example 4 with CatResult

use of io.searchbox.core.CatResult in project graylog2-server by Graylog2.

the class ClusterES6IT method currentNodeInfo.

private JsonNode currentNodeInfo() {
    final Cat nodesInfo = new Cat.NodesBuilder().setParameter("h", "id,name,host,ip").setParameter("format", "json").setParameter("full_id", "true").build();
    final CatResult catResult = JestUtils.execute(jestClient(elasticsearch), nodesInfo, () -> "Unable to retrieve current node info");
    final JsonNode result = catResult.getJsonObject().path("result");
    assertThat(result).isNotEmpty();
    return result.path(0);
}
Also used : CatResult(io.searchbox.core.CatResult) Cat(io.searchbox.core.Cat) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Aggregations

Cat (io.searchbox.core.Cat)4 CatResult (io.searchbox.core.CatResult)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 SerializationFeature (com.fasterxml.jackson.databind.SerializationFeature)1 Duration (com.github.joschi.jadconfig.util.Duration)1 Strings (com.google.common.base.Strings)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Iterators (com.google.common.collect.Iterators)1 Ints (com.google.common.primitives.Ints)1 JestClient (io.searchbox.client.JestClient)1 JestResult (io.searchbox.client.JestResult)1 Health (io.searchbox.cluster.Health)1 State (io.searchbox.cluster.State)1 Bulk (io.searchbox.core.Bulk)1 BulkResult (io.searchbox.core.BulkResult)1 Search (io.searchbox.core.Search)1 SearchResult (io.searchbox.core.SearchResult)1