Search in sources :

Example 56 with TimeValue

use of org.elasticsearch.common.unit.TimeValue in project elasticsearch-jdbc by jprante.

the class ClientTests method testClient.

@Test
public void testClient() throws IOException {
    // disable DNS caching for failover
    Security.setProperty("networkaddress.cache.ttl", "0");
    Settings settings = Settings.settingsBuilder().putArray("elasticsearch.host", new String[] { "localhost:9300", "localhost:9301" }).put("transport.type", "org.elasticsearch.transport.netty.FoundNettyTransport").put("transport.found.ssl-ports", 9443).build();
    Integer maxbulkactions = settings.getAsInt("max_bulk_actions", 10000);
    Integer maxconcurrentbulkrequests = settings.getAsInt("max_concurrent_bulk_requests", Runtime.getRuntime().availableProcessors() * 2);
    ByteSizeValue maxvolume = settings.getAsBytesSize("max_bulk_volume", ByteSizeValue.parseBytesSizeValue("10m", ""));
    TimeValue flushinterval = settings.getAsTime("flush_interval", TimeValue.timeValueSeconds(5));
    Settings.Builder clientSettings = Settings.settingsBuilder().put("cluster.name", settings.get("elasticsearch.cluster", "elasticsearch")).putArray("host", settings.getAsArray("elasticsearch.host")).put("port", settings.getAsInt("elasticsearch.port", 9300)).put("sniff", settings.getAsBoolean("elasticsearch.sniff", false)).put("autodiscover", settings.getAsBoolean("elasticsearch.autodiscover", false)).put("name", // prevents lookup of names.txt, we don't have it, and marks this node as "feeder". See also module load skipping in JDBCRiverPlugin
    "feeder").put("client.transport.ignore_cluster_name", // do not ignore cluster name setting
    false).put("client.transport.ping_timeout", //  ping timeout
    settings.getAsTime("elasticsearch.timeout", TimeValue.timeValueSeconds(10))).put("client.transport.nodes_sampler_interval", // for sniff sampling
    settings.getAsTime("elasticsearch.timeout", TimeValue.timeValueSeconds(5))).put("path.plugins", // pointing to a non-exiting folder means, this disables loading site plugins
    ".dontexist").put("path.home", System.getProperty("path.home"));
    if (settings.get("transport.type") != null) {
        clientSettings.put("transport.type", settings.get("transport.type"));
    }
    // copy found.no transport settings
    Settings foundTransportSettings = settings.getAsSettings("transport.found");
    if (foundTransportSettings != null) {
        Map<String, String> foundTransportSettingsMap = foundTransportSettings.getAsMap();
        for (Map.Entry<String, String> entry : foundTransportSettingsMap.entrySet()) {
            clientSettings.put("transport.found." + entry.getKey(), entry.getValue());
        }
    }
    try {
        ClientAPI clientAPI = ClientBuilder.builder().put(settings).put(ClientBuilder.MAX_ACTIONS_PER_REQUEST, maxbulkactions).put(ClientBuilder.MAX_CONCURRENT_REQUESTS, maxconcurrentbulkrequests).put(ClientBuilder.MAX_VOLUME_PER_REQUEST, maxvolume).put(ClientBuilder.FLUSH_INTERVAL, flushinterval).setMetric(new ElasticsearchIngestMetric()).toBulkTransportClient();
    } catch (NoNodeAvailableException e) {
    // ok
    }
}
Also used : ElasticsearchIngestMetric(org.xbib.elasticsearch.common.metrics.ElasticsearchIngestMetric) ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue) ClientAPI(org.xbib.elasticsearch.helper.client.ClientAPI) NoNodeAvailableException(org.elasticsearch.client.transport.NoNodeAvailableException) Map(java.util.Map) Settings(org.elasticsearch.common.settings.Settings) TimeValue(org.elasticsearch.common.unit.TimeValue) Test(org.testng.annotations.Test)

Example 57 with TimeValue

use of org.elasticsearch.common.unit.TimeValue in project elasticsearch by elastic.

the class SearchRequestTests method mutate.

private SearchRequest mutate(SearchRequest searchRequest) throws IOException {
    SearchRequest mutation = copyRequest(searchRequest);
    List<Runnable> mutators = new ArrayList<>();
    mutators.add(() -> mutation.indices(ArrayUtils.concat(searchRequest.indices(), new String[] { randomAsciiOfLength(10) })));
    mutators.add(() -> mutation.indicesOptions(randomValueOtherThan(searchRequest.indicesOptions(), () -> IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean()))));
    mutators.add(() -> mutation.types(ArrayUtils.concat(searchRequest.types(), new String[] { randomAsciiOfLength(10) })));
    mutators.add(() -> mutation.preference(randomValueOtherThan(searchRequest.preference(), () -> randomAsciiOfLengthBetween(3, 10))));
    mutators.add(() -> mutation.routing(randomValueOtherThan(searchRequest.routing(), () -> randomAsciiOfLengthBetween(3, 10))));
    mutators.add(() -> mutation.requestCache((randomValueOtherThan(searchRequest.requestCache(), () -> randomBoolean()))));
    mutators.add(() -> mutation.scroll(randomValueOtherThan(searchRequest.scroll(), () -> new Scroll(new TimeValue(randomNonNegativeLong() % 100000)))));
    mutators.add(() -> mutation.searchType(randomValueOtherThan(searchRequest.searchType(), () -> randomFrom(SearchType.values()))));
    mutators.add(() -> mutation.source(randomValueOtherThan(searchRequest.source(), this::createSearchSourceBuilder)));
    randomFrom(mutators).run();
    return mutation;
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) ArrayList(java.util.ArrayList) TimeValue(org.elasticsearch.common.unit.TimeValue)

Example 58 with TimeValue

use of org.elasticsearch.common.unit.TimeValue in project elasticsearch by elastic.

the class AggregationsIntegrationIT method testScroll.

public void testScroll() {
    final int size = randomIntBetween(1, 4);
    SearchResponse response = client().prepareSearch("index").setSize(size).setScroll(new TimeValue(500)).addAggregation(terms("f").field("f")).get();
    assertSearchResponse(response);
    Aggregations aggregations = response.getAggregations();
    assertNotNull(aggregations);
    Terms terms = aggregations.get("f");
    assertEquals(Math.min(numDocs, 3L), terms.getBucketByKey("0").getDocCount());
    int total = response.getHits().getHits().length;
    while (response.getHits().getHits().length > 0) {
        response = client().prepareSearchScroll(response.getScrollId()).setScroll(new TimeValue(500)).execute().actionGet();
        assertNull(response.getAggregations());
        total += response.getHits().getHits().length;
    }
    clearScroll(response.getScrollId());
    assertEquals(numDocs, total);
}
Also used : Terms(org.elasticsearch.search.aggregations.bucket.terms.Terms) TimeValue(org.elasticsearch.common.unit.TimeValue) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 59 with TimeValue

use of org.elasticsearch.common.unit.TimeValue in project graylog2-server by Graylog2.

the class Searches method scroll.

public ScrollResult scroll(String query, TimeRange range, int limit, int offset, List<String> fields, String filter) {
    final Set<String> indices = determineAffectedIndices(range, filter);
    // only request the fields we asked for otherwise we can't figure out which fields will be in the result set
    // until we've scrolled through the entire set.
    // TODO: Check if we can get away without loading the _source field.
    // http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-fields.html#search-request-fields
    // "For backwards compatibility, if the fields parameter specifies fields which are not stored , it will
    // load the _source and extract it from it. This functionality has been replaced by the source filtering
    // parameter." -- So we should look at the source filtering parameter once we switched to ES 1.x.
    final SearchRequest request = standardSearchRequest(query, indices, limit, offset, range, filter, null, false).setScroll(new TimeValue(1, TimeUnit.MINUTES)).setSize(// TODO magic numbers
    500).addSort(SortBuilders.fieldSort(SortParseElement.DOC_FIELD_NAME)).addFields(fields.toArray(new String[fields.size()])).addField(// always request the _source field because otherwise we can't access non-stored values
    "_source").request();
    if (LOG.isDebugEnabled()) {
        try {
            LOG.debug("ElasticSearch scroll query: {}", XContentHelper.convertToJson(request.source(), false));
        } catch (IOException ignored) {
        }
    }
    final SearchResponse r = c.search(request).actionGet();
    recordEsMetrics(r, range);
    return new ScrollResult(c, query, request.source(), r, fields);
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) ScrollResult(org.graylog2.indexer.results.ScrollResult) IOException(java.io.IOException) TimeValue(org.elasticsearch.common.unit.TimeValue) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 60 with TimeValue

use of org.elasticsearch.common.unit.TimeValue in project crate by crate.

the class TableStatsService method onRefreshSettings.

@Override
public void onRefreshSettings(Settings settings) {
    TimeValue newRefreshInterval = extractRefreshInterval(settings);
    if (!newRefreshInterval.equals(lastRefreshInterval)) {
        if (refreshScheduledTask != null) {
            refreshScheduledTask.cancel();
        }
        refreshScheduledTask = scheduleRefresh(newRefreshInterval);
        lastRefreshInterval = newRefreshInterval;
    }
}
Also used : TimeValue(org.elasticsearch.common.unit.TimeValue)

Aggregations

TimeValue (org.elasticsearch.common.unit.TimeValue)139 ClusterState (org.elasticsearch.cluster.ClusterState)26 IOException (java.io.IOException)24 CountDownLatch (java.util.concurrent.CountDownLatch)18 ArrayList (java.util.ArrayList)17 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)17 Settings (org.elasticsearch.common.settings.Settings)17 Supplier (org.apache.logging.log4j.util.Supplier)16 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)16 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)15 SearchResponse (org.elasticsearch.action.search.SearchResponse)15 AbstractRunnable (org.elasticsearch.common.util.concurrent.AbstractRunnable)13 Matchers.containsString (org.hamcrest.Matchers.containsString)13 Map (java.util.Map)12 TimeUnit (java.util.concurrent.TimeUnit)11 ThreadPool (org.elasticsearch.threadpool.ThreadPool)11 List (java.util.List)10 HashMap (java.util.HashMap)9 Iterator (java.util.Iterator)8 ExecutionException (java.util.concurrent.ExecutionException)8