use of org.elasticsearch.common.compress.CompressedXContent in project elasticsearch by elastic.
the class GeoContextMappingTests method testIndexingWithContextList.
public void testIndexingWithContextList() throws Exception {
String mapping = jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("completion").field("type", "completion").startArray("contexts").startObject().field("name", "ctx").field("type", "geo").endObject().endArray().endObject().endObject().endObject().endObject().string();
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type1", new CompressedXContent(mapping));
FieldMapper fieldMapper = defaultMapper.mappers().getMapper("completion");
MappedFieldType completionFieldType = fieldMapper.fieldType();
ParsedDocument parsedDocument = defaultMapper.parse("test", "type1", "1", jsonBuilder().startObject().startObject("completion").array("input", "suggestion5", "suggestion6", "suggestion7").startObject("contexts").startArray("ctx").startObject().field("lat", 43.6624803).field("lon", -79.3863353).endObject().startObject().field("lat", 43.6624718).field("lon", -79.3873227).endObject().endArray().endObject().field("weight", 5).endObject().endObject().bytes());
IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name());
assertContextSuggestFields(fields, 3);
}
use of org.elasticsearch.common.compress.CompressedXContent in project elasticsearch by elastic.
the class PercolateQueryBuilderTests method initializeAdditionalMappings.
@Override
protected void initializeAdditionalMappings(MapperService mapperService) throws IOException {
queryField = randomAsciiOfLength(4);
docType = randomAsciiOfLength(4);
mapperService.merge("query_type", new CompressedXContent(PutMappingRequest.buildFromSimplifiedDef("query_type", queryField, "type=percolator").string()), MapperService.MergeReason.MAPPING_UPDATE, false);
mapperService.merge(docType, new CompressedXContent(PutMappingRequest.buildFromSimplifiedDef(docType, STRING_FIELD_NAME, "type=text").string()), MapperService.MergeReason.MAPPING_UPDATE, false);
}
use of org.elasticsearch.common.compress.CompressedXContent in project elasticsearch by elastic.
the class PercolatorFieldMapperTests method testMultiplePercolatorFields.
// multiple percolator fields are allowed in the mapping, but only one field can be used at index time.
public void testMultiplePercolatorFields() throws Exception {
String typeName = "another_type";
String percolatorMapper = XContentFactory.jsonBuilder().startObject().startObject(typeName).startObject("_field_names").field("enabled", false).endObject().startObject("properties").startObject("query_field1").field("type", "percolator").endObject().startObject("query_field2").field("type", "percolator").endObject().endObject().endObject().endObject().string();
mapperService.merge(typeName, new CompressedXContent(percolatorMapper), MapperService.MergeReason.MAPPING_UPDATE, true);
QueryBuilder queryBuilder = matchQuery("field", "value");
ParsedDocument doc = mapperService.documentMapper(typeName).parse("test", typeName, "1", jsonBuilder().startObject().field("query_field1", queryBuilder).field("query_field2", queryBuilder).endObject().bytes());
// also includes all other meta fields
assertThat(doc.rootDoc().getFields().size(), equalTo(14));
BytesRef queryBuilderAsBytes = doc.rootDoc().getField("query_field1.query_builder_field").binaryValue();
assertQueryBuilder(queryBuilderAsBytes, queryBuilder);
queryBuilderAsBytes = doc.rootDoc().getField("query_field2.query_builder_field").binaryValue();
assertQueryBuilder(queryBuilderAsBytes, queryBuilder);
}
use of org.elasticsearch.common.compress.CompressedXContent in project elasticsearch by elastic.
the class PercolatorFieldMapperTests method init.
@Before
public void init() throws Exception {
indexService = createIndex("test", Settings.EMPTY);
mapperService = indexService.mapperService();
String mapper = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("_field_names").field("enabled", false).endObject().startObject("properties").startObject("field").field("type", "text").endObject().startObject("field1").field("type", "text").endObject().startObject("field2").field("type", "text").endObject().startObject("_field3").field("type", "text").endObject().startObject("field4").field("type", "text").endObject().startObject("number_field").field("type", "long").endObject().startObject("date_field").field("type", "date").endObject().endObject().endObject().endObject().string();
mapperService.merge("type", new CompressedXContent(mapper), MapperService.MergeReason.MAPPING_UPDATE, true);
}
use of org.elasticsearch.common.compress.CompressedXContent in project elasticsearch by elastic.
the class PercolatorFieldMapperTests method testEmptyName.
public void testEmptyName() throws Exception {
// after 5.x
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("").field("type", "percolator").endObject().endObject().endObject().endObject().string();
DocumentMapperParser parser = mapperService.documentMapperParser();
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> parser.parse("type1", new CompressedXContent(mapping)));
assertThat(e.getMessage(), containsString("name cannot be empty string"));
// before 5.x
Version oldVersion = VersionUtils.randomVersionBetween(getRandom(), Version.V_2_0_0, Version.V_2_3_5);
Settings oldIndexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, oldVersion).build();
DocumentMapperParser parser2x = createIndex("test_old", oldIndexSettings).mapperService().documentMapperParser();
DocumentMapper defaultMapper = parser2x.parse("type1", new CompressedXContent(mapping));
assertEquals(mapping, defaultMapper.mappingSource().string());
}
Aggregations