use of org.elasticsearch.common.xcontent.XContentType in project crate by crate.
the class ColumnPolicyIntegrationTest method testStrictPartitionedTableInsert.
@Test
public void testStrictPartitionedTableInsert() throws Exception {
execute("create table numbers (" + " num int, " + " odd boolean," + " prime boolean" + ") partitioned by (odd) with (column_policy='strict', number_of_replicas=0)");
ensureYellow();
GetIndexTemplatesResponse response = client().admin().indices().prepareGetTemplates(PartitionName.templateName(null, "numbers")).execute().actionGet();
assertThat(response.getIndexTemplates().size(), is(1));
IndexTemplateMetaData template = response.getIndexTemplates().get(0);
CompressedXContent mappingStr = template.mappings().get(Constants.DEFAULT_MAPPING_TYPE);
assertThat(mappingStr, is(notNullValue()));
Tuple<XContentType, Map<String, Object>> typeAndMap = XContentHelper.convertToMap(mappingStr.compressedReference(), false);
@SuppressWarnings("unchecked") Map<String, Object> mapping = (Map<String, Object>) typeAndMap.v2().get(Constants.DEFAULT_MAPPING_TYPE);
assertThat(String.valueOf(mapping.get("dynamic")), is(ColumnPolicy.STRICT.value()));
execute("insert into numbers (num, odd, prime) values (?, ?, ?)", new Object[] { 6, true, false });
execute("refresh table numbers");
MappingMetaData partitionMetaData = clusterService().state().metaData().indices().get(new PartitionName("numbers", Arrays.asList(new BytesRef("true"))).asIndexName()).getMappings().get(Constants.DEFAULT_MAPPING_TYPE);
assertThat(String.valueOf(partitionMetaData.getSourceAsMap().get("dynamic")), is(ColumnPolicy.STRICT.value()));
expectedException.expect(SQLActionException.class);
expectedException.expectMessage("Column perfect unknown");
execute("insert into numbers (num, odd, prime, perfect) values (?, ?, ?, ?)", new Object[] { 28, true, false, true });
}
use of org.elasticsearch.common.xcontent.XContentType in project elasticsearch by elastic.
the class SearchHitTests method testFromXContent.
public void testFromXContent() throws IOException {
SearchHit searchHit = createTestItem(true);
boolean humanReadable = randomBoolean();
XContentType xContentType = randomFrom(XContentType.values());
BytesReference originalBytes = toXContent(searchHit, xContentType, humanReadable);
SearchHit parsed;
try (XContentParser parser = createParser(xContentType.xContent(), originalBytes)) {
// jump to first START_OBJECT
parser.nextToken();
parsed = SearchHit.fromXContent(parser);
assertEquals(XContentParser.Token.END_OBJECT, parser.currentToken());
assertNull(parser.nextToken());
}
assertToXContentEquivalent(originalBytes, toXContent(parsed, xContentType, humanReadable), xContentType);
}
use of org.elasticsearch.common.xcontent.XContentType in project elasticsearch by elastic.
the class SearchHitsTests method testFromXContent.
public void testFromXContent() throws IOException {
SearchHits searchHits = createTestItem();
XContentType xcontentType = randomFrom(XContentType.values());
boolean humanReadable = randomBoolean();
BytesReference originalBytes = toXContent(searchHits, xcontentType, humanReadable);
SearchHits parsed;
try (XContentParser parser = createParser(xcontentType.xContent(), originalBytes)) {
parsed = SearchHits.fromXContent(parser);
assertEquals(XContentParser.Token.END_OBJECT, parser.currentToken());
assertEquals(XContentParser.Token.END_OBJECT, parser.nextToken());
assertNull(parser.nextToken());
}
assertToXContentEquivalent(originalBytes, toXContent(parsed, xcontentType, humanReadable), xcontentType);
}
use of org.elasticsearch.common.xcontent.XContentType in project elasticsearch by elastic.
the class FiltersAggsRewriteIT method testWrapperQueryIsRewritten.
public void testWrapperQueryIsRewritten() throws IOException {
createIndex("test", Settings.EMPTY, "test", "title", "type=text");
client().prepareIndex("test", "test", "1").setSource("title", "foo bar baz").get();
client().prepareIndex("test", "test", "2").setSource("title", "foo foo foo").get();
client().prepareIndex("test", "test", "3").setSource("title", "bar baz bax").get();
client().admin().indices().prepareRefresh("test").get();
XContentType xContentType = randomFrom(XContentType.values());
BytesReference bytesReference;
try (XContentBuilder builder = XContentFactory.contentBuilder(xContentType)) {
builder.startObject();
{
builder.startObject("terms");
{
builder.array("title", "foo");
}
builder.endObject();
}
builder.endObject();
bytesReference = builder.bytes();
}
FiltersAggregationBuilder builder = new FiltersAggregationBuilder("titles", new FiltersAggregator.KeyedFilter("titleterms", new WrapperQueryBuilder(bytesReference)));
SearchResponse searchResponse = client().prepareSearch("test").setSize(0).addAggregation(builder).get();
assertEquals(3, searchResponse.getHits().getTotalHits());
InternalFilters filters = searchResponse.getAggregations().get("titles");
assertEquals(1, filters.getBuckets().size());
assertEquals(2, filters.getBuckets().get(0).getDocCount());
}
use of org.elasticsearch.common.xcontent.XContentType in project elasticsearch by elastic.
the class HighlightFieldTests method testFromXContent.
public void testFromXContent() throws IOException {
HighlightField highlightField = createTestItem();
XContentType xcontentType = randomFrom(XContentType.values());
XContentBuilder builder = XContentFactory.contentBuilder(xcontentType);
if (randomBoolean()) {
builder.prettyPrint();
}
// we need to wrap xContent output in proper object to create a parser for it
builder.startObject();
builder = highlightField.toXContent(builder, ToXContent.EMPTY_PARAMS);
builder.endObject();
XContentParser parser = createParser(builder);
// skip to the opening object token, fromXContent advances from here and starts with the field name
parser.nextToken();
parser.nextToken();
HighlightField parsedField = HighlightField.fromXContent(parser);
assertEquals(highlightField, parsedField);
if (highlightField.fragments() != null) {
assertEquals(XContentParser.Token.END_ARRAY, parser.currentToken());
}
assertEquals(XContentParser.Token.END_OBJECT, parser.nextToken());
assertNull(parser.nextToken());
}
Aggregations