本文整理汇总了Java中org.elasticsearch.common.unit.TimeValue.parseTimeValue方法的典型用法代码示例。如果您正苦于以下问题:Java TimeValue.parseTimeValue方法的具体用法?Java TimeValue.parseTimeValue怎么用?Java TimeValue.parseTimeValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.common.unit.TimeValue
的用法示例。
在下文中一共展示了TimeValue.parseTimeValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testInitialSearchParamsMisc
import org.elasticsearch.common.unit.TimeValue; //导入方法依赖的package包/类
public void testInitialSearchParamsMisc() {
SearchRequest searchRequest = new SearchRequest().source(new SearchSourceBuilder());
Version remoteVersion = Version.fromId(between(0, Version.CURRENT.id));
TimeValue scroll = null;
if (randomBoolean()) {
scroll = TimeValue.parseTimeValue(randomPositiveTimeValue(), "test");
searchRequest.scroll(scroll);
}
int size = between(0, Integer.MAX_VALUE);
searchRequest.source().size(size);
Boolean fetchVersion = null;
if (randomBoolean()) {
fetchVersion = randomBoolean();
searchRequest.source().version(fetchVersion);
}
Map<String, String> params = initialSearchParams(searchRequest, remoteVersion);
assertThat(params, scroll == null ? not(hasKey("scroll")) : hasEntry("scroll", scroll.toString()));
assertThat(params, hasEntry("size", Integer.toString(size)));
assertThat(params, fetchVersion == null || fetchVersion == true ? hasEntry("version", null) : not(hasEntry("version", null)));
}
示例2: createInternal
import org.elasticsearch.common.unit.TimeValue; //导入方法依赖的package包/类
@Override
protected PipelineAggregator createInternal(Map<String, Object> metaData) throws IOException {
DocValueFormat formatter;
if (format != null) {
formatter = new DocValueFormat.Decimal(format);
} else {
formatter = DocValueFormat.RAW;
}
Long xAxisUnits = null;
if (units != null) {
DateTimeUnit dateTimeUnit = DateHistogramAggregationBuilder.DATE_FIELD_UNITS.get(units);
if (dateTimeUnit != null) {
xAxisUnits = dateTimeUnit.field(DateTimeZone.UTC).getDurationField().getUnitMillis();
} else {
TimeValue timeValue = TimeValue.parseTimeValue(units, null, getClass().getSimpleName() + ".unit");
if (timeValue != null) {
xAxisUnits = timeValue.getMillis();
}
}
}
return new DerivativePipelineAggregator(name, bucketsPaths, formatter, gapPolicy, xAxisUnits, metaData);
}
示例3: parseTimeValue
import org.elasticsearch.common.unit.TimeValue; //导入方法依赖的package包/类
public static TimeValue parseTimeValue(String s, TimeValue minValue, String key) {
TimeValue timeValue = TimeValue.parseTimeValue(s, null, key);
if (timeValue.millis() < minValue.millis()) {
throw new IllegalArgumentException("Failed to parse value [" + s + "] for setting [" + key + "] must be >= " + minValue);
}
return timeValue;
}
示例4: timeSetting
import org.elasticsearch.common.unit.TimeValue; //导入方法依赖的package包/类
public static Setting<TimeValue> timeSetting(String key, Function<Settings, TimeValue> defaultValue, TimeValue minValue,
Property... properties) {
return new Setting<>(key, (s) -> defaultValue.apply(s).getStringRep(), (s) -> {
TimeValue timeValue = TimeValue.parseTimeValue(s, null, key);
if (timeValue.millis() < minValue.millis()) {
throw new IllegalArgumentException("Failed to parse value [" + s + "] for setting [" + key + "] must be >= " + minValue);
}
return timeValue;
}, properties);
}
示例5: testSettingExpireAfterAccess
import org.elasticsearch.common.unit.TimeValue; //导入方法依赖的package包/类
public void testSettingExpireAfterAccess() {
IllegalArgumentException iae =
expectThrows(IllegalArgumentException.class, () -> CacheBuilder.builder().setExpireAfterAccess(TimeValue.MINUS_ONE));
assertThat(iae.getMessage(), containsString("expireAfterAccess <="));
iae = expectThrows(IllegalArgumentException.class, () -> CacheBuilder.builder().setExpireAfterAccess(TimeValue.ZERO));
assertThat(iae.getMessage(), containsString("expireAfterAccess <="));
final TimeValue timeValue = TimeValue.parseTimeValue(randomPositiveTimeValue(), "");
Cache<Object, Object> cache = CacheBuilder.builder().setExpireAfterAccess(timeValue).build();
assertEquals(timeValue.getNanos(), cache.getExpireAfterAccessNanos());
}
示例6: testSettingExpireAfterWrite
import org.elasticsearch.common.unit.TimeValue; //导入方法依赖的package包/类
public void testSettingExpireAfterWrite() {
IllegalArgumentException iae =
expectThrows(IllegalArgumentException.class, () -> CacheBuilder.builder().setExpireAfterWrite(TimeValue.MINUS_ONE));
assertThat(iae.getMessage(), containsString("expireAfterWrite <="));
iae = expectThrows(IllegalArgumentException.class, () -> CacheBuilder.builder().setExpireAfterWrite(TimeValue.ZERO));
assertThat(iae.getMessage(), containsString("expireAfterWrite <="));
final TimeValue timeValue = TimeValue.parseTimeValue(randomPositiveTimeValue(), "");
Cache<Object, Object> cache = CacheBuilder.builder().setExpireAfterWrite(timeValue).build();
assertEquals(timeValue.getNanos(), cache.getExpireAfterWriteNanos());
}
示例7: getConnection
import org.elasticsearch.common.unit.TimeValue; //导入方法依赖的package包/类
private static ElasticConnection getConnection(String hostname, int transportPort, String flushIntervalString, BulkProcessor.Listener listener) {
System.setProperty("es.set.netty.runtime.available.processors", "false");
TimeValue flushInterval = TimeValue.parseTimeValue(flushIntervalString, TimeValue.timeValueSeconds(5), "flush");
Client client = getClient(hostname, transportPort);
BulkProcessor bulkProcessor = BulkProcessor.builder(client, listener)
.setFlushInterval(flushInterval)
.setBulkActions(10)
.setConcurrentRequests(10)
.build();
return new ElasticConnection(client, bulkProcessor);
}
示例8: visitStringLiteral
import org.elasticsearch.common.unit.TimeValue; //导入方法依赖的package包/类
@Override
protected TimeValue visitStringLiteral(StringLiteral node, Context context) {
try {
return TimeValue.parseTimeValue(node.getValue(), DEFAULT_VALUE, context.settingName);
} catch (ElasticsearchParseException e) {
throw new IllegalArgumentException(
String.format(Locale.ENGLISH, "Invalid time value '%s'", node.getValue()));
}
}
示例9: parseDateVariable
import org.elasticsearch.common.unit.TimeValue; //导入方法依赖的package包/类
private AbstractDistanceScoreFunction parseDateVariable(String fieldName, XContentParser parser, QueryParseContext parseContext,
DateFieldMapper.DateFieldType dateFieldType, MultiValueMode mode) throws IOException {
XContentParser.Token token;
String parameterName = null;
String scaleString = null;
String originString = null;
String offsetString = "0d";
double decay = 0.5;
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
if (token == XContentParser.Token.FIELD_NAME) {
parameterName = parser.currentName();
} else if (parameterName.equals(DecayFunctionBuilder.SCALE)) {
scaleString = parser.text();
} else if (parameterName.equals(DecayFunctionBuilder.ORIGIN)) {
originString = parser.text();
} else if (parameterName.equals(DecayFunctionBuilder.DECAY)) {
decay = parser.doubleValue();
} else if (parameterName.equals(DecayFunctionBuilder.OFFSET)) {
offsetString = parser.text();
} else {
throw new ElasticsearchParseException("parameter [{}] not supported!", parameterName);
}
}
long origin = SearchContext.current().nowInMillis();
if (originString != null) {
origin = dateFieldType.parseToMilliseconds(originString, false, null, null);
}
if (scaleString == null) {
throw new ElasticsearchParseException("[{}] must be set for date fields.", DecayFunctionBuilder.SCALE);
}
TimeValue val = TimeValue.parseTimeValue(scaleString, TimeValue.timeValueHours(24), getClass().getSimpleName() + ".scale");
double scale = val.getMillis();
val = TimeValue.parseTimeValue(offsetString, TimeValue.timeValueHours(24), getClass().getSimpleName() + ".offset");
double offset = val.getMillis();
IndexNumericFieldData numericFieldData = parseContext.getForField(dateFieldType);
return new NumericFieldDataScoreFunction(origin, scale, decay, offset, getDecayFunction(), numericFieldData, mode);
}
示例10: getTTLFromScriptContext
import org.elasticsearch.common.unit.TimeValue; //导入方法依赖的package包/类
private TimeValue getTTLFromScriptContext(Map<String, Object> ctx) {
Object fetchedTTL = ctx.get("_ttl");
if (fetchedTTL != null) {
if (fetchedTTL instanceof Number) {
return new TimeValue(((Number) fetchedTTL).longValue());
}
return TimeValue.parseTimeValue((String) fetchedTTL, null, "_ttl");
}
return null;
}
示例11: getScrollKeepAlive
import org.elasticsearch.common.unit.TimeValue; //导入方法依赖的package包/类
public TimeValue getScrollKeepAlive() {
String value = graphConfiguration.getString(GraphConfiguration.SEARCH_INDEX_PROP_PREFIX + "." + QUERY_SCROLL_KEEP_ALIVE, QUERY_SCROLL_KEEP_ALIVE_DEFAULT);
return TimeValue.parseTimeValue(value, null, "");
}
示例12: testScrollParams
import org.elasticsearch.common.unit.TimeValue; //导入方法依赖的package包/类
public void testScrollParams() {
TimeValue scroll = TimeValue.parseTimeValue(randomPositiveTimeValue(), "test");
assertThat(scrollParams(scroll), hasEntry("scroll", scroll.toString()));
}
示例13: parseDateVariable
import org.elasticsearch.common.unit.TimeValue; //导入方法依赖的package包/类
private AbstractDistanceScoreFunction parseDateVariable(XContentParser parser, QueryShardContext context,
MappedFieldType dateFieldType, MultiValueMode mode) throws IOException {
XContentParser.Token token;
String parameterName = null;
String scaleString = null;
String originString = null;
String offsetString = "0d";
double decay = 0.5;
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
if (token == XContentParser.Token.FIELD_NAME) {
parameterName = parser.currentName();
} else if (DecayFunctionBuilder.SCALE.equals(parameterName)) {
scaleString = parser.text();
} else if (DecayFunctionBuilder.ORIGIN.equals(parameterName)) {
originString = parser.text();
} else if (DecayFunctionBuilder.DECAY.equals(parameterName)) {
decay = parser.doubleValue();
} else if (DecayFunctionBuilder.OFFSET.equals(parameterName)) {
offsetString = parser.text();
} else {
throw new ElasticsearchParseException("parameter [{}] not supported!", parameterName);
}
}
long origin;
if (originString == null) {
origin = context.nowInMillis();
} else {
origin = ((DateFieldMapper.DateFieldType) dateFieldType).parseToMilliseconds(originString, false, null, null, context);
}
if (scaleString == null) {
throw new ElasticsearchParseException("[{}] must be set for date fields.", DecayFunctionBuilder.SCALE);
}
TimeValue val = TimeValue.parseTimeValue(scaleString, TimeValue.timeValueHours(24),
DecayFunctionParser.class.getSimpleName() + ".scale");
double scale = val.getMillis();
val = TimeValue.parseTimeValue(offsetString, TimeValue.timeValueHours(24), DecayFunctionParser.class.getSimpleName() + ".offset");
double offset = val.getMillis();
IndexNumericFieldData numericFieldData = context.getForField(dateFieldType);
return new NumericFieldDataScoreFunction(origin, scale, decay, offset, getDecayFunction(), numericFieldData, mode);
}
示例14: nodeTimeValue
import org.elasticsearch.common.unit.TimeValue; //导入方法依赖的package包/类
public static TimeValue nodeTimeValue(Object node) {
if (node instanceof Number) {
return TimeValue.timeValueMillis(((Number) node).longValue());
}
return TimeValue.parseTimeValue(node.toString(), null, XContentMapValues.class.getSimpleName() + ".nodeTimeValue");
}
示例15: setTimeout
import org.elasticsearch.common.unit.TimeValue; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public final Request setTimeout(String timeout) {
this.timeout = TimeValue.parseTimeValue(timeout, null, getClass().getSimpleName() + ".timeout");
return (Request) this;
}