本文整理汇总了Java中org.elasticsearch.common.xcontent.ToXContent.MapParams方法的典型用法代码示例。如果您正苦于以下问题:Java ToXContent.MapParams方法的具体用法?Java ToXContent.MapParams怎么用?Java ToXContent.MapParams使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.common.xcontent.ToXContent
的用法示例。
在下文中一共展示了ToXContent.MapParams方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testFromXContent
import org.elasticsearch.common.xcontent.ToXContent; //导入方法依赖的package包/类
public void testFromXContent() throws IOException {
ToXContent.Params params = new ToXContent.MapParams(Collections.singletonMap(RestSearchAction.TYPED_KEYS_PARAM, "true"));
Suggest suggest = createTestItem();
XContentType xContentType = randomFrom(XContentType.values());
boolean humanReadable = randomBoolean();
BytesReference originalBytes = toXContent(suggest, xContentType, params, humanReadable);
Suggest parsed;
try (XContentParser parser = createParser(xContentType.xContent(), originalBytes)) {
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
ensureFieldName(parser, parser.nextToken(), Suggest.NAME);
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
parsed = Suggest.fromXContent(parser);
assertEquals(XContentParser.Token.END_OBJECT, parser.currentToken());
assertEquals(XContentParser.Token.END_OBJECT, parser.nextToken());
assertNull(parser.nextToken());
}
assertEquals(suggest.size(), parsed.size());
for (Suggestion suggestion : suggest) {
Suggestion<? extends Entry<? extends Option>> parsedSuggestion = parsed.getSuggestion(suggestion.getName());
assertNotNull(parsedSuggestion);
assertEquals(suggestion.getClass(), parsedSuggestion.getClass());
}
assertToXContentEquivalent(originalBytes, toXContent(parsed, xContentType, params, humanReadable), xContentType);
}
示例2: testFromXContent
import org.elasticsearch.common.xcontent.ToXContent; //导入方法依赖的package包/类
@SuppressWarnings({ "rawtypes" })
public void testFromXContent() throws IOException {
ToXContent.Params params = new ToXContent.MapParams(Collections.singletonMap(RestSearchAction.TYPED_KEYS_PARAM, "true"));
for (Class<Suggestion<? extends Entry<? extends Option>>> type : SUGGESTION_TYPES) {
Suggestion suggestion = createTestItem(type);
XContentType xContentType = randomFrom(XContentType.values());
boolean humanReadable = randomBoolean();
BytesReference originalBytes = toXContent(suggestion, xContentType, params, humanReadable);
Suggestion parsed;
try (XContentParser parser = createParser(xContentType.xContent(), originalBytes)) {
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
ensureExpectedToken(XContentParser.Token.FIELD_NAME, parser.nextToken(), parser::getTokenLocation);
parsed = Suggestion.fromXContent(parser);
assertEquals(XContentParser.Token.END_OBJECT, parser.nextToken());
assertNull(parser.nextToken());
}
assertEquals(suggestion.getName(), parsed.getName());
assertEquals(suggestion.getEntries().size(), parsed.getEntries().size());
// We don't parse size via xContent, instead we set it to -1 on the client side
assertEquals(-1, parsed.getSize());
assertToXContentEquivalent(originalBytes, toXContent(parsed, xContentType, params, humanReadable), xContentType);
}
}
示例3: testInvalidLevel
import org.elasticsearch.common.xcontent.ToXContent; //导入方法依赖的package包/类
public void testInvalidLevel() {
final NodeIndicesStats stats = new NodeIndicesStats();
final String level = randomAsciiOfLength(16);
final ToXContent.Params params = new ToXContent.MapParams(Collections.singletonMap("level", level));
final IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> stats.toXContent(null, params));
assertThat(
e,
hasToString(containsString("level parameter must be one of [indices] or [node] or [shards] but was [" + level + "]")));
}
示例4: testInvalidLevel
import org.elasticsearch.common.xcontent.ToXContent; //导入方法依赖的package包/类
public void testInvalidLevel() {
final IndicesStatsResponse response = new IndicesStatsResponse();
final String level = randomAsciiOfLength(16);
final ToXContent.Params params = new ToXContent.MapParams(Collections.singletonMap("level", level));
final IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> response.toXContent(null, params));
assertThat(
e,
hasToString(containsString("level parameter must be one of [cluster] or [indices] or [shards] but was [" + level + "]")));
}