本文整理汇总了Java中org.elasticsearch.common.ParsingException类的典型用法代码示例。如果您正苦于以下问题:Java ParsingException类的具体用法?Java ParsingException怎么用?Java ParsingException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ParsingException类属于org.elasticsearch.common包,在下文中一共展示了ParsingException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testParseRequestFailure
import org.elasticsearch.common.ParsingException; //导入依赖的package包/类
public void testParseRequestFailure() throws Exception {
AtomicBoolean called = new AtomicBoolean();
Consumer<Response> checkResponse = r -> {
assertFalse(r.isTimedOut());
assertNull(r.getScrollId());
assertEquals(0, r.getTotalHits());
assertThat(r.getFailures(), hasSize(1));
assertThat(r.getFailures().get(0).getReason(), instanceOf(ParsingException.class));
ParsingException failure = (ParsingException) r.getFailures().get(0).getReason();
assertEquals("Unknown key for a VALUE_STRING in [invalid].", failure.getMessage());
assertEquals(2, failure.getLineNumber());
assertEquals(14, failure.getColumnNumber());
called.set(true);
};
sourceWithMockedRemoteCall("request_failure.json").doStart(checkResponse);
assertTrue(called.get());
called.set(false);
sourceWithMockedRemoteCall("request_failure.json").doStartNextScroll("scroll", timeValueMillis(0), checkResponse);
assertTrue(called.get());
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:RemoteScrollableHitSourceTests.java
示例2: testTwoAggs
import org.elasticsearch.common.ParsingException; //导入依赖的package包/类
public void testTwoAggs() throws Exception {
assumeFalse("Test only makes sense if XContent parser doesn't have strict duplicate checks enabled",
XContent.isStrictDuplicateDetectionEnabled());
XContentBuilder source = JsonXContent.contentBuilder()
.startObject()
.startObject("by_date")
.startObject("date_histogram")
.field("field", "timestamp")
.field("interval", "month")
.endObject()
.startObject("aggs")
.startObject("tag_count")
.startObject("cardinality")
.field("field", "tag")
.endObject()
.endObject()
.endObject()
.startObject("aggs") // 2nd "aggs": illegal
.startObject("tag_count2")
.startObject("cardinality")
.field("field", "tag")
.endObject()
.endObject()
.endObject()
.endObject()
.endObject();
XContentParser parser = createParser(source);
QueryParseContext parseContext = new QueryParseContext(parser);
assertSame(XContentParser.Token.START_OBJECT, parser.nextToken());
Exception e = expectThrows(ParsingException.class, () -> AggregatorFactories.parseAggregators(parseContext));
assertThat(e.toString(), containsString("Found two sub aggregation definitions under [by_date]"));
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:33,代码来源:AggregatorFactoriesTests.java
示例3: testParseFailsWithMultipleFields
import org.elasticsearch.common.ParsingException; //导入依赖的package包/类
public void testParseFailsWithMultipleFields() throws IOException {
String json =
"{\n" +
" \"wildcard\": {\n" +
" \"user1\": {\n" +
" \"wildcard\": \"ki*y\"\n" +
" },\n" +
" \"user2\": {\n" +
" \"wildcard\": \"ki*y\"\n" +
" }\n" +
" }\n" +
"}";
ParsingException e = expectThrows(ParsingException.class, () -> parseQuery(json));
assertEquals("[wildcard] query doesn't support multiple fields, found [user1] and [user2]", e.getMessage());
String shortJson =
"{\n" +
" \"wildcard\": {\n" +
" \"user1\": \"ki*y\",\n" +
" \"user2\": \"ki*y\"\n" +
" }\n" +
"}";
e = expectThrows(ParsingException.class, () -> parseQuery(shortJson));
assertEquals("[wildcard] query doesn't support multiple fields, found [user1] and [user2]", e.getMessage());
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:WildcardQueryBuilderTests.java
示例4: testParseFailsWithMultipleFields
import org.elasticsearch.common.ParsingException; //导入依赖的package包/类
public void testParseFailsWithMultipleFields() throws IOException {
String json =
"{\n" +
" \"prefix\": {\n" +
" \"user1\": {\n" +
" \"value\": \"ki\"\n" +
" },\n" +
" \"user2\": {\n" +
" \"value\": \"ki\"\n" +
" }\n" +
" }\n" +
"}";
ParsingException e = expectThrows(ParsingException.class, () -> parseQuery(json));
assertEquals("[prefix] query doesn't support multiple fields, found [user1] and [user2]", e.getMessage());
String shortJson =
"{\n" +
" \"prefix\": {\n" +
" \"user1\": \"ki\",\n" +
" \"user2\": \"ki\"\n" +
" }\n" +
"}";
e = expectThrows(ParsingException.class, () -> parseQuery(shortJson));
assertEquals("[prefix] query doesn't support multiple fields, found [user1] and [user2]", e.getMessage());
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:PrefixQueryBuilderTests.java
示例5: parse
import org.elasticsearch.common.ParsingException; //导入依赖的package包/类
public static TeardownSection parse(XContentParser parser) throws IOException {
TeardownSection teardownSection = new TeardownSection();
teardownSection.setSkipSection(SkipSection.parseIfNext(parser));
while (parser.currentToken() != XContentParser.Token.END_ARRAY) {
ParserUtils.advanceToFieldName(parser);
if (!"do".equals(parser.currentName())) {
throw new ParsingException(parser.getTokenLocation(),
"section [" + parser.currentName() + "] not supported within teardown section");
}
teardownSection.addDoSection(DoSection.parse(parser));
parser.nextToken();
}
parser.nextToken();
return teardownSection;
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:TeardownSection.java
示例6: parse
import org.elasticsearch.common.ParsingException; //导入依赖的package包/类
public static ClientYamlTestSection parse(XContentParser parser) throws IOException {
ParserUtils.advanceToFieldName(parser);
ClientYamlTestSection testSection = new ClientYamlTestSection(parser.getTokenLocation(), parser.currentName());
try {
parser.nextToken();
testSection.setSkipSection(SkipSection.parseIfNext(parser));
while (parser.currentToken() != XContentParser.Token.END_ARRAY) {
ParserUtils.advanceToFieldName(parser);
testSection.addExecutableSection(ExecutableSection.parse(parser));
}
if (parser.nextToken() != XContentParser.Token.END_OBJECT) {
throw new IllegalArgumentException("malformed section [" + testSection.getName() + "] expected ["
+ XContentParser.Token.END_OBJECT + "] but was [" + parser.currentToken() + "]");
}
parser.nextToken();
return testSection;
} catch (Exception e) {
throw new ParsingException(parser.getTokenLocation(), "Error parsing test named [" + testSection.getName() + "]", e);
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:ClientYamlTestSection.java
示例7: testParseIndexAndIndicesThrowsError
import org.elasticsearch.common.ParsingException; //导入依赖的package包/类
public void testParseIndexAndIndicesThrowsError() throws IOException {
XContentBuilder b = XContentBuilder.builder(randomFrom(XContentType.values()).xContent());
b.startObject(); {
b.startObject(randomFrom("add", "remove")); {
b.field("index", randomAsciiOfLength(5));
b.array("indices", generateRandomStringArray(10, 5, false, false));
b.field("alias", randomAsciiOfLength(5));
}
b.endObject();
}
b.endObject();
try (XContentParser parser = createParser(b)) {
Exception e = expectThrows(ParsingException.class, () -> AliasActions.PARSER.apply(parser, null));
assertThat(e.getCause().getCause(), instanceOf(IllegalArgumentException.class));
assertEquals("Only one of [index] and [indices] is supported", e.getCause().getCause().getMessage());
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:AliasActionsTests.java
示例8: testPreTagsWithoutPostTags
import org.elasticsearch.common.ParsingException; //导入依赖的package包/类
public void testPreTagsWithoutPostTags() throws IOException {
ParsingException e = expectParseThrows(ParsingException.class, "{\n" +
" \"pre_tags\" : [\"<a>\"]\n" +
"}\n");
assertEquals("pre_tags are set but post_tags are not set", e.getMessage());
e = expectParseThrows(ParsingException.class, "{\n" +
" \"fields\" : {\n" +
" \"body\" : {\n" +
" \"pre_tags\" : [\"<a>\"]\n" +
" }\n" +
" }\n" +
"}\n");
assertEquals("[highlight] failed to parse field [fields]", e.getMessage());
assertEquals("[fields] failed to parse field [body]", e.getCause().getMessage());
assertEquals("pre_tags are set but post_tags are not set", e.getCause().getCause().getMessage());
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:HighlightBuilderTests.java
示例9: testParseFailsWithMultipleFields
import org.elasticsearch.common.ParsingException; //导入依赖的package包/类
public void testParseFailsWithMultipleFields() throws IOException {
String json = "{\n" +
" \"match_phrase\" : {\n" +
" \"message1\" : {\n" +
" \"query\" : \"this is a test\"\n" +
" },\n" +
" \"message2\" : {\n" +
" \"query\" : \"this is a test\"\n" +
" }\n" +
" }\n" +
"}";
ParsingException e = expectThrows(ParsingException.class, () -> parseQuery(json));
assertEquals("[match_phrase] query doesn't support multiple fields, found [message1] and [message2]", e.getMessage());
String shortJson = "{\n" +
" \"match_phrase\" : {\n" +
" \"message1\" : \"this is a test\",\n" +
" \"message2\" : \"this is a test\"\n" +
" }\n" +
"}";
e = expectThrows(ParsingException.class, () -> parseQuery(shortJson));
assertEquals("[match_phrase] query doesn't support multiple fields, found [message1] and [message2]", e.getMessage());
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:MatchPhraseQueryBuilderTests.java
示例10: parseMissingAndAdd
import org.elasticsearch.common.ParsingException; //导入依赖的package包/类
private void parseMissingAndAdd(final String aggregationName, final String currentFieldName,
XContentParser parser, final Map<String, Object> missing) throws IOException {
XContentParser.Token token = parser.currentToken();
if (token == null) {
token = parser.nextToken();
}
if (token == XContentParser.Token.FIELD_NAME) {
final String fieldName = parser.currentName();
if (missing.containsKey(fieldName)) {
throw new ParsingException(parser.getTokenLocation(),
"Missing field [" + fieldName + "] already defined as [" + missing.get(fieldName)
+ "] in [" + aggregationName + "].");
}
parser.nextToken();
missing.put(fieldName, parser.objectText());
} else {
throw new ParsingException(parser.getTokenLocation(),
"Unexpected token " + token + " [" + currentFieldName + "] in [" + aggregationName + "]");
}
}
开发者ID:scaleborn,项目名称:elasticsearch-linear-regression,代码行数:22,代码来源:MultiValuesSourceParser.java
示例11: parseOrder
import org.elasticsearch.common.ParsingException; //导入依赖的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
示例12: fromXContent
import org.elasticsearch.common.ParsingException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static Suggestion<? extends Entry<? extends Option>> fromXContent(XContentParser parser) throws IOException {
ensureExpectedToken(XContentParser.Token.FIELD_NAME, parser.currentToken(), parser::getTokenLocation);
String typeAndName = parser.currentName();
// we need to extract the type prefix from the name and throw error if it is not present
int delimiterPos = typeAndName.indexOf(InternalAggregation.TYPED_KEYS_DELIMITER);
String type;
String name;
if (delimiterPos > 0) {
type = typeAndName.substring(0, delimiterPos);
name = typeAndName.substring(delimiterPos + 1);
} else {
throw new ParsingException(parser.getTokenLocation(),
"Cannot parse suggestion response without type information. Set [" + RestSearchAction.TYPED_KEYS_PARAM
+ "] parameter on the request to ensure the type information is added to the response output");
}
return parser.namedObject(Suggestion.class, type, name);
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:Suggest.java
示例13: fromXContent
import org.elasticsearch.common.ParsingException; //导入依赖的package包/类
public static SmoothingModel fromXContent(XContentParser parser) throws IOException {
XContentParser.Token token;
String fieldName = null;
SmoothingModel model = null;
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
if (token == XContentParser.Token.FIELD_NAME) {
fieldName = parser.currentName();
} else if (token == XContentParser.Token.START_OBJECT) {
if (LinearInterpolation.PARSE_FIELD.match(fieldName)) {
model = LinearInterpolation.fromXContent(parser);
} else if (Laplace.PARSE_FIELD.match(fieldName)) {
model = Laplace.fromXContent(parser);
} else if (StupidBackoff.PARSE_FIELD.match(fieldName)) {
model = StupidBackoff.fromXContent(parser);
} else {
throw new IllegalArgumentException("suggester[phrase] doesn't support object field [" + fieldName + "]");
}
} else {
throw new ParsingException(parser.getTokenLocation(),
"[smoothing] unknown token [" + token + "] after [" + fieldName + "]");
}
}
return model;
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:SmoothingModel.java
示例14: fromXContent
import org.elasticsearch.common.ParsingException; //导入依赖的package包/类
public static StoredFieldsContext fromXContent(String fieldName, QueryParseContext context) throws IOException {
XContentParser parser = context.parser();
XContentParser.Token token = parser.currentToken();
if (token == XContentParser.Token.VALUE_STRING) {
return fromList(Collections.singletonList(parser.text()));
} else if (token == XContentParser.Token.START_ARRAY) {
ArrayList<String> list = new ArrayList<>();
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
list.add(parser.text());
}
return fromList(list);
} else {
throw new ParsingException(parser.getTokenLocation(),
"Expected [" + XContentParser.Token.VALUE_STRING + "] or ["
+ XContentParser.Token.START_ARRAY + "] in [" + fieldName + "] but found [" + token + "]",
parser.getTokenLocation());
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:StoredFieldsContext.java
示例15: fromXContent
import org.elasticsearch.common.ParsingException; //导入依赖的package包/类
public static HighlightField fromXContent(XContentParser parser) throws IOException {
ensureExpectedToken(XContentParser.Token.FIELD_NAME, parser.currentToken(), parser::getTokenLocation);
String fieldName = parser.currentName();
Text[] fragments = null;
XContentParser.Token token = parser.nextToken();
if (token == XContentParser.Token.START_ARRAY) {
List<Text> values = new ArrayList<>();
while (parser.nextToken() != XContentParser.Token.END_ARRAY) {
values.add(new Text(parser.text()));
}
fragments = values.toArray(new Text[values.size()]);
} else if (token == XContentParser.Token.VALUE_NULL) {
fragments = null;
} else {
throw new ParsingException(parser.getTokenLocation(),
"unexpected token type [" + token + "]");
}
return new HighlightField(fieldName, fragments);
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:HighlightField.java
示例16: testParseFailsWithMultipleFieldsWhenOneIsDate
import org.elasticsearch.common.ParsingException; //导入依赖的package包/类
public void testParseFailsWithMultipleFieldsWhenOneIsDate() throws IOException {
String json =
"{\n" +
" \"range\": {\n" +
" \"age\": {\n" +
" \"gte\": 30,\n" +
" \"lte\": 40\n" +
" },\n" +
" \"" + DATE_FIELD_NAME + "\": {\n" +
" \"gte\": \"2016-09-13 05:01:14\"\n" +
" }\n" +
" }\n" +
" }";
ParsingException e = expectThrows(ParsingException.class, () -> parseQuery(json));
assertEquals("[range] query doesn't support multiple fields, found [age] and [" + DATE_FIELD_NAME + "]", e.getMessage());
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:RangeQueryBuilderTests.java
示例17: testParseFailsWithMultipleFields
import org.elasticsearch.common.ParsingException; //导入依赖的package包/类
public void testParseFailsWithMultipleFields() throws IOException {
String json = "{\n" +
" \"term\" : {\n" +
" \"message1\" : {\n" +
" \"value\" : \"this\"\n" +
" },\n" +
" \"message2\" : {\n" +
" \"value\" : \"this\"\n" +
" }\n" +
" }\n" +
"}";
ParsingException e = expectThrows(ParsingException.class, () -> parseQuery(json));
assertEquals("[term] query doesn't support multiple fields, found [message1] and [message2]", e.getMessage());
String shortJson = "{\n" +
" \"term\" : {\n" +
" \"message1\" : \"this\",\n" +
" \"message2\" : \"this\"\n" +
" }\n" +
"}";
e = expectThrows(ParsingException.class, () -> parseQuery(shortJson));
assertEquals("[term] query doesn't support multiple fields, found [message1] and [message2]", e.getMessage());
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:TermQueryBuilderTests.java
示例18: fromXContent
import org.elasticsearch.common.ParsingException; //导入依赖的package包/类
public static ScriptScoreFunctionBuilder fromXContent(QueryParseContext parseContext)
throws IOException, ParsingException {
XContentParser parser = parseContext.parser();
Script script = null;
String currentFieldName = null;
XContentParser.Token token;
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
if (token == XContentParser.Token.FIELD_NAME) {
currentFieldName = parser.currentName();
} else {
if (Script.SCRIPT_PARSE_FIELD.match(currentFieldName)) {
script = Script.parse(parser);
} else {
throw new ParsingException(parser.getTokenLocation(), NAME + " query does not support [" + currentFieldName + "]");
}
}
}
if (script == null) {
throw new ParsingException(parser.getTokenLocation(), NAME + " requires 'script' field");
}
return new ScriptScoreFunctionBuilder(script);
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:ScriptScoreFunctionBuilder.java
示例19: parseVariable
import org.elasticsearch.common.ParsingException; //导入依赖的package包/类
private AbstractDistanceScoreFunction parseVariable(String fieldName, XContentParser parser, QueryShardContext context,
MultiValueMode mode) throws IOException {
//the field must exist, else we cannot read the value for the doc later
MappedFieldType fieldType = context.fieldMapper(fieldName);
if (fieldType == null) {
throw new ParsingException(parser.getTokenLocation(), "unknown field [{}]", fieldName);
}
// dates and time and geo need special handling
parser.nextToken();
if (fieldType instanceof DateFieldMapper.DateFieldType) {
return parseDateVariable(parser, context, fieldType, mode);
} else if (fieldType instanceof GeoPointFieldType) {
return parseGeoVariable(parser, context, fieldType, mode);
} else if (fieldType instanceof NumberFieldMapper.NumberFieldType) {
return parseNumberVariable(parser, context, fieldType, mode);
} else {
throw new ParsingException(parser.getTokenLocation(), "field [{}] is of type [{}], but only numeric types are supported.",
fieldName, fieldType);
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:DecayFunctionBuilder.java
示例20: testParseFailsWithMultipleFields
import org.elasticsearch.common.ParsingException; //导入依赖的package包/类
public void testParseFailsWithMultipleFields() throws IOException {
String json = "{\n" +
" \"span_term\" : {\n" +
" \"message1\" : {\n" +
" \"term\" : \"this\"\n" +
" },\n" +
" \"message2\" : {\n" +
" \"term\" : \"this\"\n" +
" }\n" +
" }\n" +
"}";
ParsingException e = expectThrows(ParsingException.class, () -> parseQuery(json));
assertEquals("[span_term] query doesn't support multiple fields, found [message1] and [message2]", e.getMessage());
String shortJson = "{\n" +
" \"span_term\" : {\n" +
" \"message1\" : \"this\",\n" +
" \"message2\" : \"this\"\n" +
" }\n" +
"}";
e = expectThrows(ParsingException.class, () -> parseQuery(shortJson));
assertEquals("[span_term] query doesn't support multiple fields, found [message1] and [message2]", e.getMessage());
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:SpanTermQueryBuilderTests.java
注:本文中的org.elasticsearch.common.ParsingException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论