Java Code Examples for org.elasticsearch.common.unit.TimeValue#timeValueSeconds()

The following examples show how to use org.elasticsearch.common.unit.TimeValue#timeValueSeconds() . 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: Util.java    From flume-elasticsearch-sink with Apache License 2.0 6 votes vote down vote up
/**
 * Returns TimeValue based on the given interval
 * Interval can be in minutes, seconds, mili seconds
 */
public static TimeValue getTimeValue(String interval, String defaultValue) {
    TimeValue timeValue = null;
    String timeInterval = interval != null ? interval : defaultValue;
    logger.trace("Time interval is [{}] ", timeInterval);
    if (timeInterval != null) {
        Integer time = Integer.valueOf(timeInterval.substring(0, timeInterval.length() - 1));
        String unit = timeInterval.substring(timeInterval.length() - 1);
        UnitEnum unitEnum = UnitEnum.fromString(unit);
        switch (unitEnum) {
            case MINUTE:
                timeValue = TimeValue.timeValueMinutes(time);
                break;
            case SECOND:
                timeValue = TimeValue.timeValueSeconds(time);
                break;
            case MILI_SECOND:
                timeValue = TimeValue.timeValueMillis(time);
                break;
            default:
                logger.error("Unit is incorrect, please check the Time Value unit: " + unit);
        }
    }
    return timeValue;
}
 
Example 2
Source File: ElasticSearchUtilImpl.java    From metacat with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor.
 *
 * @param client              elastic search client
 * @param config              config
 * @param metacatJson         json utility
 * @param registry            spectator registry
 */
public ElasticSearchUtilImpl(
    @Nullable final Client client,
    final Config config,
    final MetacatJson metacatJson,
    final Registry registry) {
    this.config = config;
    this.client = client;
    this.metacatJson = metacatJson;
    this.esIndex = config.getEsIndex();
    this.registry = registry;
    this.esCallTimeout = TimeValue.timeValueSeconds(config.getElasticSearchCallTimeout());
    this.esBulkCallTimeout = TimeValue.timeValueSeconds(config.getElasticSearchBulkCallTimeout());
}
 
Example 3
Source File: DumpSaver.java    From elasticshell with Apache License 2.0 5 votes vote down vote up
void dumpSave(Client client, Builder builder) throws IOException {

        TimeValue scrollDuration = TimeValue.timeValueSeconds(30);
        SearchResponse searchResponse = client.prepareSearch(builder.indices())
                .setTypes(builder.types()).setSearchType(SearchType.SCAN)
                .setQuery(builder.query()).setSize(100).setScroll(scrollDuration).execute().actionGet();

        OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(builder.path(), true), builder.charset());

        int i = 0;
        try {
            while (true) {
                searchResponse = client.prepareSearchScroll(searchResponse.getScrollId())
                        .setScroll(scrollDuration).execute().actionGet();

                if (searchResponse.getHits().hits().length == 0) {
                    break;
                }

                for (SearchHit hit : searchResponse.getHits()) {
                    Document document = Document.fromSource(hit.sourceAsString(), hit.index(), hit.type(), hit.id());
                    writer.write(document.getDump());
                    i++;
                    writer.write('\n');
                }
            }
        } finally {
            writer.close();
            console.println("Saved " + i + " documents to " + builder.path());
        }

    }
 
Example 4
Source File: CrateTableSettings.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public TimeValue defaultValue() {
    return TimeValue.timeValueSeconds(5);
}
 
Example 5
Source File: CrateTableSettings.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public TimeValue defaultValue() {
    return TimeValue.timeValueSeconds(5);
}