本文整理汇总了Java中org.elasticsearch.common.xcontent.XContentParser.Token类的典型用法代码示例。如果您正苦于以下问题:Java Token类的具体用法?Java Token怎么用?Java Token使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Token类属于org.elasticsearch.common.xcontent.XContentParser包,在下文中一共展示了Token类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: setInline
import org.elasticsearch.common.xcontent.XContentParser.Token; //导入依赖的package包/类
/**
* Since inline scripts can accept code rather than just an id, they must also be able
* to handle template parsing, hence the need for custom parsing code. Templates can
* consist of either an {@link String} or a JSON object. If a JSON object is discovered
* then the content type option must also be saved as a compiler option.
*/
private void setInline(XContentParser parser) {
try {
if (type != null) {
throwOnlyOneOfType();
}
type = ScriptType.INLINE;
if (parser.currentToken() == Token.START_OBJECT) {
//this is really for search templates, that need to be converted to json format
XContentBuilder builder = XContentFactory.jsonBuilder();
idOrCode = builder.copyCurrentStructure(parser).string();
options.put(CONTENT_TYPE_OPTION, XContentType.JSON.mediaType());
} else {
idOrCode = parser.text();
}
} catch (IOException exception) {
throw new UncheckedIOException(exception);
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:Script.java
示例2: parseOrder
import org.elasticsearch.common.xcontent.XContentParser.Token; //导入依赖的package包/类
private static InternalOrder parseOrder(XContentParser parser, QueryParseContext context) throws IOException {
InternalOrder order = null;
Token token;
String currentFieldName = null;
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
if (token == XContentParser.Token.FIELD_NAME) {
currentFieldName = parser.currentName();
} else if (token == XContentParser.Token.VALUE_STRING) {
String dir = parser.text();
boolean asc = "asc".equals(dir);
if (!asc && !"desc".equals(dir)) {
throw new ParsingException(parser.getTokenLocation(), "Unknown order direction: [" + dir
+ "]. Should be either [asc] or [desc]");
}
order = resolveOrder(currentFieldName, asc);
}
}
return order;
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:DateHistogramAggregationBuilder.java
示例3: testParseGeoPointGeohash
import org.elasticsearch.common.xcontent.XContentParser.Token; //导入依赖的package包/类
public void testParseGeoPointGeohash() throws IOException {
for (int i = 0; i < 100; i++) {
int geoHashLength = randomIntBetween(1, GeoHashUtils.PRECISION);
StringBuilder geohashBuilder = new StringBuilder(geoHashLength);
for (int j = 0; j < geoHashLength; j++) {
geohashBuilder.append(BASE_32[randomInt(BASE_32.length - 1)]);
}
XContentBuilder json = jsonBuilder().startObject().field("geohash", geohashBuilder.toString()).endObject();
XContentParser parser = createParser(json);
parser.nextToken();
GeoPoint point = GeoUtils.parseGeoPoint(parser);
assertThat(point.lat(), allOf(lessThanOrEqualTo(90.0), greaterThanOrEqualTo(-90.0)));
assertThat(point.lon(), allOf(lessThanOrEqualTo(180.0), greaterThanOrEqualTo(-180.0)));
json = jsonBuilder().startObject().field("geohash", geohashBuilder.toString()).endObject();
parser = createParser(json);
while (parser.currentToken() != Token.VALUE_STRING) {
parser.nextToken();
}
point = GeoUtils.parseGeoPoint(parser);
assertThat(point.lat(), allOf(lessThanOrEqualTo(90.0), greaterThanOrEqualTo(-90.0)));
assertThat(point.lon(), allOf(lessThanOrEqualTo(180.0), greaterThanOrEqualTo(-180.0)));
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:GeoUtilsTests.java
示例4: verifyNodeDecisionPrologue
import org.elasticsearch.common.xcontent.XContentParser.Token; //导入依赖的package包/类
private String verifyNodeDecisionPrologue(XContentParser parser) throws IOException {
assertEquals(Token.START_OBJECT, parser.nextToken());
parser.nextToken();
assertEquals("node_id", parser.currentName());
parser.nextToken();
assertNotNull(parser.text());
parser.nextToken();
assertEquals("node_name", parser.currentName());
parser.nextToken();
String nodeName = parser.text();
assertNotNull(nodeName);
parser.nextToken();
assertEquals("transport_address", parser.currentName());
parser.nextToken();
assertNotNull(parser.text());
parser.nextToken();
assertEquals("node_decision", parser.currentName());
parser.nextToken();
return nodeName;
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:ClusterAllocationExplainIT.java
示例5: verifyDeciders
import org.elasticsearch.common.xcontent.XContentParser.Token; //导入依赖的package包/类
private boolean verifyDeciders(XContentParser parser, AllocationDecision allocationDecision) throws IOException {
assertEquals(Token.START_ARRAY, parser.nextToken());
boolean atLeastOneMatchingDecisionFound = false;
while (parser.nextToken() != Token.END_ARRAY) {
assertEquals(Token.START_OBJECT, parser.currentToken());
parser.nextToken();
assertEquals("decider", parser.currentName());
parser.nextToken();
assertNotNull(parser.text());
parser.nextToken();
assertEquals("decision", parser.currentName());
parser.nextToken();
String decisionText = parser.text();
if ((allocationDecision == AllocationDecision.NO && decisionText.equals("NO")
|| (allocationDecision == AllocationDecision.THROTTLED && decisionText.equals("THROTTLE")))) {
atLeastOneMatchingDecisionFound = true;
}
assertNotNull(decisionText);
parser.nextToken();
assertEquals("explanation", parser.currentName());
parser.nextToken();
assertNotNull(parser.text());
assertEquals(Token.END_OBJECT, parser.nextToken());
}
return atLeastOneMatchingDecisionFound;
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:ClusterAllocationExplainIT.java
示例6: parseQuery
import org.elasticsearch.common.xcontent.XContentParser.Token; //导入依赖的package包/类
@Override
public FieldQuery parseQuery(String name, XContentParser parser) throws IOException, ElasticsearchParseException {
Iterable<? extends CharSequence> values;
Token token = parser.currentToken();
if (token == Token.START_ARRAY) {
ArrayList<String> list = new ArrayList<>();
while ((token = parser.nextToken()) != Token.END_ARRAY) {
list.add(parser.text());
}
values = list;
} else if (token == Token.VALUE_NULL) {
values = defaultValues;
} else {
values = Collections.singleton(parser.text());
}
return new FieldQuery(name, values);
}
开发者ID:baidu,项目名称:Elasticsearch,代码行数:19,代码来源:CategoryContextMapping.java
示例7: parse
import org.elasticsearch.common.xcontent.XContentParser.Token; //导入依赖的package包/类
@Override
public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException {
XContentParser parser = parseContext.parser();
Token token = parser.nextToken();
if (!MATCH_NAME.equals(parser.currentName()) || token != XContentParser.Token.FIELD_NAME) {
throw new QueryParsingException(parseContext, "spanMultiTerm must have [" + MATCH_NAME + "] multi term query clause");
}
token = parser.nextToken();
if (token != XContentParser.Token.START_OBJECT) {
throw new QueryParsingException(parseContext, "spanMultiTerm must have [" + MATCH_NAME + "] multi term query clause");
}
Query subQuery = parseContext.parseInnerQuery();
if (!(subQuery instanceof MultiTermQuery)) {
throw new QueryParsingException(parseContext, "spanMultiTerm [" + MATCH_NAME + "] must be of type multi term query");
}
parser.nextToken();
return new SpanMultiTermQueryWrapper<>((MultiTermQuery) subQuery);
}
开发者ID:baidu,项目名称:Elasticsearch,代码行数:23,代码来源:SpanMultiTermQueryParser.java
示例8: parse
import org.elasticsearch.common.xcontent.XContentParser.Token; //导入依赖的package包/类
public static Term parse(XContentParser parser, String name) {
try {
Term completion = new Term(name);
Token token;
String currentFieldName = null;
while ((token = parser.nextToken()) != END_OBJECT) {
if (token == FIELD_NAME) {
currentFieldName = parser.currentName();
} else if (token.isValue()) {
if("text".equals(currentFieldName)) {
completion.text = parser.text();
} else if("offset".equals(currentFieldName)) {
completion.offset = parser.intValue();
} else if("length".equals(currentFieldName)) {
completion.length = parser.intValue();
}
} else if (token == START_ARRAY && "options".equals(currentFieldName)) {
completion.options = parseOptions(parser);
}
}
return completion;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
开发者ID:obourgain,项目名称:elasticsearch-http,代码行数:26,代码来源:Term.java
示例9: parseOption
import org.elasticsearch.common.xcontent.XContentParser.Token; //导入依赖的package包/类
protected static Option parseOption(XContentParser parser) throws IOException {
Token token;
String currentFieldName = null;
Option option = new Option();
while ((token = parser.nextToken()) != Token.END_OBJECT) {
if (token == Token.FIELD_NAME) {
currentFieldName = parser.currentName();
} else if (token.isValue()) {
if ("text".equals(currentFieldName)) {
option.text = parser.text();
} else if ("freq".equals(currentFieldName)) {
option.freq = parser.longValue();
} else if ("score".equals(currentFieldName)) {
option.score = parser.floatValue();
}
}
}
return option;
}
开发者ID:obourgain,项目名称:elasticsearch-http,代码行数:20,代码来源:Term.java
示例10: parse
import org.elasticsearch.common.xcontent.XContentParser.Token; //导入依赖的package包/类
public static Completion parse(XContentParser parser, String name) {
try {
Completion completion = new Completion(name);
Token token;
String currentFieldName = null;
while ((token = parser.nextToken()) != END_OBJECT) {
if (token == FIELD_NAME) {
currentFieldName = parser.currentName();
} else if (token.isValue()) {
if("text".equals(currentFieldName)) {
completion.text = parser.text();
} else if("offset".equals(currentFieldName)) {
completion.offset = parser.intValue();
} else if("length".equals(currentFieldName)) {
completion.length = parser.intValue();
}
} else if (token == START_ARRAY && "options".equals(currentFieldName)) {
completion.options = parseOptions(parser);
}
}
return completion;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
开发者ID:obourgain,项目名称:elasticsearch-http,代码行数:26,代码来源:Completion.java
示例11: parseOption
import org.elasticsearch.common.xcontent.XContentParser.Token; //导入依赖的package包/类
protected static Option parseOption(XContentParser parser) throws IOException {
Token token;
String currentFieldName = null;
Option option = new Option();
while ((token = parser.nextToken()) != Token.END_OBJECT) {
if (token == Token.FIELD_NAME) {
currentFieldName = parser.currentName();
} else if (token.isValue()) {
if ("text".equals(currentFieldName)) {
option.text = parser.text();
} else if ("score".equals(currentFieldName)) {
option.score = parser.floatValue();
}
} else if (token == Token.START_OBJECT && "payload".equals(currentFieldName)) {
try (XContentBuilder docBuilder = XContentFactory.contentBuilder(XContentType.JSON)) {
docBuilder.copyCurrentStructure(parser);
option.payload = docBuilder.bytes().toUtf8();
}
}
}
return option;
}
开发者ID:obourgain,项目名称:elasticsearch-http,代码行数:23,代码来源:Completion.java
示例12: parse
import org.elasticsearch.common.xcontent.XContentParser.Token; //导入依赖的package包/类
public static Phrase parse(XContentParser parser, String name) {
try {
Phrase completion = new Phrase(name);
Token token;
String currentFieldName = null;
while ((token = parser.nextToken()) != END_OBJECT) {
if (token == FIELD_NAME) {
currentFieldName = parser.currentName();
} else if (token.isValue()) {
if("text".equals(currentFieldName)) {
completion.text = parser.text();
} else if("offset".equals(currentFieldName)) {
completion.offset = parser.intValue();
} else if("length".equals(currentFieldName)) {
completion.length = parser.intValue();
}
} else if (token == START_ARRAY && "options".equals(currentFieldName)) {
completion.options = parseOptions(parser);
}
}
return completion;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
开发者ID:obourgain,项目名称:elasticsearch-http,代码行数:26,代码来源:Phrase.java
示例13: parseOption
import org.elasticsearch.common.xcontent.XContentParser.Token; //导入依赖的package包/类
protected static Option parseOption(XContentParser parser) throws IOException {
Token token;
String currentFieldName = null;
Option option = new Option();
while ((token = parser.nextToken()) != Token.END_OBJECT) {
if (token == Token.FIELD_NAME) {
currentFieldName = parser.currentName();
} else if (token.isValue()) {
if ("text".equals(currentFieldName)) {
option.text = parser.text();
} else if ("collate".equals(currentFieldName)) {
option.collate = parser.booleanValue();
} else if ("score".equals(currentFieldName)) {
option.score = parser.floatValue();
} else if ("highlighted".equals(currentFieldName)) {
option.highlighted = parser.text();
}
}
}
return option;
}
开发者ID:obourgain,项目名称:elasticsearch-http,代码行数:22,代码来源:Phrase.java
示例14: fromXContent
import org.elasticsearch.common.xcontent.XContentParser.Token; //导入依赖的package包/类
public JobEvent fromXContent(XContentParser parser) throws IOException {
//DateMathParser dateParser = new DateMathParser(Joda.forPattern("dateOptionalTime"), TimeUnit.MILLISECONDS);
Long startTimestamp = null;
String currentFieldName = null;
Token token;
while ((token = parser.nextToken()) != END_OBJECT) {
if (token == FIELD_NAME) {
currentFieldName = parser.currentName();
} else if (token.isValue() || token == VALUE_NULL) {
if ("started".equals(currentFieldName)) {
startTimestamp = Long.parseLong(parser.text());
}
} else if (token == START_ARRAY) {
List<String> values = newArrayList();
while ((parser.nextToken()) != END_ARRAY) {
values.add(parser.text());
}
}
}
return new JobEvent().timestamp(startTimestamp);
}
开发者ID:jprante,项目名称:elasticsearch-gatherer,代码行数:22,代码来源:JobEvent.java
示例15: setCode
import org.elasticsearch.common.xcontent.XContentParser.Token; //导入依赖的package包/类
/**
* Since stored scripts can accept templates rather than just scripts, they must also be able
* to handle template parsing, hence the need for custom parsing code. Templates can
* consist of either an {@link String} or a JSON object. If a JSON object is discovered
* then the content type option must also be saved as a compiler option.
*/
private void setCode(XContentParser parser) {
try {
if (parser.currentToken() == Token.START_OBJECT) {
//this is really for search templates, that need to be converted to json format
XContentBuilder builder = XContentFactory.jsonBuilder();
code = builder.copyCurrentStructure(parser).string();
options.put(Script.CONTENT_TYPE_OPTION, XContentType.JSON.mediaType());
} else {
code = parser.text();
}
} catch (IOException exception) {
throw new UncheckedIOException(exception);
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:StoredScriptSource.java
示例16: parseRange
import org.elasticsearch.common.xcontent.XContentParser.Token; //导入依赖的package包/类
private static Range parseRange(XContentParser parser, QueryParseContext context) throws IOException {
String fromAsStr = null;
String toAsStr = null;
double from = 0.0;
double to = Double.POSITIVE_INFINITY;
String key = null;
String toOrFromOrKey = null;
Token token;
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
if (token == XContentParser.Token.FIELD_NAME) {
toOrFromOrKey = parser.currentName();
} else if (token == XContentParser.Token.VALUE_NUMBER) {
if (Range.FROM_FIELD.match(toOrFromOrKey)) {
from = parser.doubleValue();
} else if (Range.TO_FIELD.match(toOrFromOrKey)) {
to = parser.doubleValue();
}
} else if (token == XContentParser.Token.VALUE_STRING) {
if (Range.KEY_FIELD.match(toOrFromOrKey)) {
key = parser.text();
} else if (Range.FROM_FIELD.match(toOrFromOrKey)) {
fromAsStr = parser.text();
} else if (Range.TO_FIELD.match(toOrFromOrKey)) {
toAsStr = parser.text();
}
}
}
if (fromAsStr != null || toAsStr != null) {
return new Range(key, Double.parseDouble(fromAsStr), Double.parseDouble(toAsStr));
} else {
return new Range(key, from, to);
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:34,代码来源:GeoDistanceAggregationBuilder.java
示例17: parseRange
import org.elasticsearch.common.xcontent.XContentParser.Token; //导入依赖的package包/类
private static Range parseRange(XContentParser parser, QueryParseContext context) throws IOException {
String key = null;
String from = null;
String to = null;
String mask = null;
if (parser.currentToken() != Token.START_OBJECT) {
throw new ParsingException(parser.getTokenLocation(), "[ranges] must contain objects, but hit a " + parser.currentToken());
}
while (parser.nextToken() != Token.END_OBJECT) {
if (parser.currentToken() == Token.FIELD_NAME) {
continue;
}
if (RangeAggregator.Range.KEY_FIELD.match(parser.currentName())) {
key = parser.text();
} else if (RangeAggregator.Range.FROM_FIELD.match(parser.currentName())) {
from = parser.textOrNull();
} else if (RangeAggregator.Range.TO_FIELD.match(parser.currentName())) {
to = parser.textOrNull();
} else if (MASK_FIELD.match(parser.currentName())) {
mask = parser.text();
} else {
throw new ParsingException(parser.getTokenLocation(), "Unexpected ip range parameter: [" + parser.currentName() + "]");
}
}
if (mask != null) {
if (key == null) {
key = mask;
}
return new Range(key, mask);
} else {
return new Range(key, from, to);
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:35,代码来源:IpRangeAggregationBuilder.java
示例18: parseQueryContext
import org.elasticsearch.common.xcontent.XContentParser.Token; //导入依赖的package包/类
/**
* Parses query contexts for this mapper
*/
public final List<InternalQueryContext> parseQueryContext(QueryParseContext context) throws IOException, ElasticsearchParseException {
List<T> queryContexts = new ArrayList<>();
XContentParser parser = context.parser();
Token token = parser.nextToken();
if (token == Token.START_OBJECT || token == Token.VALUE_STRING) {
queryContexts.add(fromXContent(context));
} else if (token == Token.START_ARRAY) {
while (parser.nextToken() != Token.END_ARRAY) {
queryContexts.add(fromXContent(context));
}
}
return toInternalQueryContexts(queryContexts);
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:ContextMapping.java
示例19: fromXContent
import org.elasticsearch.common.xcontent.XContentParser.Token; //导入依赖的package包/类
public static SmoothingModel fromXContent(XContentParser parser) throws IOException {
XContentParser.Token token;
String fieldName = null;
double alpha = DEFAULT_LAPLACE_ALPHA;
while ((token = parser.nextToken()) != Token.END_OBJECT) {
if (token == XContentParser.Token.FIELD_NAME) {
fieldName = parser.currentName();
}
if (token.isValue() && ALPHA_FIELD.match(fieldName)) {
alpha = parser.doubleValue();
}
}
return new Laplace(alpha);
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:15,代码来源:Laplace.java
示例20: fromXContent
import org.elasticsearch.common.xcontent.XContentParser.Token; //导入依赖的package包/类
public static LinearInterpolation fromXContent(XContentParser parser) throws IOException {
XContentParser.Token token;
String fieldName = null;
double trigramLambda = 0.0;
double bigramLambda = 0.0;
double unigramLambda = 0.0;
while ((token = parser.nextToken()) != Token.END_OBJECT) {
if (token == XContentParser.Token.FIELD_NAME) {
fieldName = parser.currentName();
} else if (token.isValue()) {
if (TRIGRAM_FIELD.match(fieldName)) {
trigramLambda = parser.doubleValue();
if (trigramLambda < 0) {
throw new IllegalArgumentException("trigram_lambda must be positive");
}
} else if (BIGRAM_FIELD.match(fieldName)) {
bigramLambda = parser.doubleValue();
if (bigramLambda < 0) {
throw new IllegalArgumentException("bigram_lambda must be positive");
}
} else if (UNIGRAM_FIELD.match(fieldName)) {
unigramLambda = parser.doubleValue();
if (unigramLambda < 0) {
throw new IllegalArgumentException("unigram_lambda must be positive");
}
} else {
throw new IllegalArgumentException(
"suggester[phrase][smoothing][linear] doesn't support field [" + fieldName + "]");
}
} else {
throw new ParsingException(parser.getTokenLocation(),
"[" + NAME + "] unknown token [" + token + "] after [" + fieldName + "]");
}
}
return new LinearInterpolation(trigramLambda, bigramLambda, unigramLambda);
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:37,代码来源:LinearInterpolation.java
注:本文中的org.elasticsearch.common.xcontent.XContentParser.Token类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论