Search in sources :

Example 6 with MapperRegistry

use of org.elasticsearch.indices.mapper.MapperRegistry in project elasticsearch by elastic.

the class MetaDataIndexUpgradeServiceTests method testIsUpgraded.

public void testIsUpgraded() {
    MetaDataIndexUpgradeService service = new MetaDataIndexUpgradeService(Settings.EMPTY, xContentRegistry(), new MapperRegistry(Collections.emptyMap(), Collections.emptyMap()), IndexScopedSettings.DEFAULT_SCOPED_SETTINGS);
    IndexMetaData src = newIndexMeta("foo", Settings.builder().put("index.refresh_interval", "-200").build());
    assertFalse(service.isUpgraded(src));
    Version version = VersionUtils.randomVersionBetween(random(), VersionUtils.getFirstVersion(), VersionUtils.getPreviousVersion());
    src = newIndexMeta("foo", Settings.builder().put(IndexMetaData.SETTING_VERSION_UPGRADED, version).build());
    assertFalse(service.isUpgraded(src));
    src = newIndexMeta("foo", Settings.builder().put(IndexMetaData.SETTING_VERSION_UPGRADED, Version.CURRENT).build());
    assertTrue(service.isUpgraded(src));
}
Also used : MapperRegistry(org.elasticsearch.indices.mapper.MapperRegistry) Version(org.elasticsearch.Version)

Example 7 with MapperRegistry

use of org.elasticsearch.indices.mapper.MapperRegistry in project elasticsearch by elastic.

the class ExternalFieldMapperTests method testExternalValuesWithMultifield.

public void testExternalValuesWithMultifield() throws Exception {
    Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.CURRENT);
    Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build();
    IndexService indexService = createIndex("test", settings);
    Map<String, Mapper.TypeParser> mapperParsers = new HashMap<>();
    mapperParsers.put(ExternalMapperPlugin.EXTERNAL, new ExternalMapper.TypeParser(ExternalMapperPlugin.EXTERNAL, "foo"));
    mapperParsers.put(TextFieldMapper.CONTENT_TYPE, new TextFieldMapper.TypeParser());
    mapperParsers.put(KeywordFieldMapper.CONTENT_TYPE, new KeywordFieldMapper.TypeParser());
    MapperRegistry mapperRegistry = new MapperRegistry(mapperParsers, Collections.emptyMap());
    Supplier<QueryShardContext> queryShardContext = () -> {
        return indexService.newQueryShardContext(0, null, () -> {
            throw new UnsupportedOperationException();
        });
    };
    DocumentMapperParser parser = new DocumentMapperParser(indexService.getIndexSettings(), indexService.mapperService(), indexService.getIndexAnalyzers(), indexService.xContentRegistry(), indexService.similarityService(), mapperRegistry, queryShardContext);
    DocumentMapper documentMapper = parser.parse("type", new CompressedXContent(XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("field").field("type", ExternalMapperPlugin.EXTERNAL).startObject("fields").startObject("field").field("type", "text").field("store", true).startObject("fields").startObject("raw").field("type", "keyword").field("store", true).endObject().endObject().endObject().endObject().endObject().endObject().endObject().endObject().string()));
    ParsedDocument doc = documentMapper.parse("test", "type", "1", XContentFactory.jsonBuilder().startObject().field("field", "1234").endObject().bytes());
    assertThat(doc.rootDoc().getField("field.bool"), notNullValue());
    assertThat(doc.rootDoc().getField("field.bool").stringValue(), is("T"));
    assertThat(doc.rootDoc().getField("field.point"), notNullValue());
    GeoPoint point = new GeoPoint().resetFromIndexableField(doc.rootDoc().getField("field.point"));
    assertThat(point.lat(), closeTo(42.0, 1E-5));
    assertThat(point.lon(), closeTo(51.0, 1E-5));
    IndexableField shape = doc.rootDoc().getField("field.shape");
    assertThat(shape, notNullValue());
    IndexableField field = doc.rootDoc().getField("field.field");
    assertThat(field, notNullValue());
    assertThat(field.stringValue(), is("foo"));
    IndexableField raw = doc.rootDoc().getField("field.field.raw");
    assertThat(raw, notNullValue());
    assertThat(raw.binaryValue(), is(new BytesRef("foo")));
}
Also used : IndexService(org.elasticsearch.index.IndexService) HashMap(java.util.HashMap) IndexableField(org.apache.lucene.index.IndexableField) GeoPoint(org.elasticsearch.common.geo.GeoPoint) Version(org.elasticsearch.Version) MapperRegistry(org.elasticsearch.indices.mapper.MapperRegistry) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) QueryShardContext(org.elasticsearch.index.query.QueryShardContext) Settings(org.elasticsearch.common.settings.Settings) BytesRef(org.apache.lucene.util.BytesRef)

Example 8 with MapperRegistry

use of org.elasticsearch.indices.mapper.MapperRegistry in project elasticsearch by elastic.

the class ExternalFieldMapperTests method testExternalValues.

public void testExternalValues() throws Exception {
    Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.CURRENT);
    Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build();
    IndexService indexService = createIndex("test", settings);
    MapperRegistry mapperRegistry = new MapperRegistry(Collections.singletonMap(ExternalMapperPlugin.EXTERNAL, new ExternalMapper.TypeParser(ExternalMapperPlugin.EXTERNAL, "foo")), Collections.singletonMap(ExternalMetadataMapper.CONTENT_TYPE, new ExternalMetadataMapper.TypeParser()));
    Supplier<QueryShardContext> queryShardContext = () -> {
        return indexService.newQueryShardContext(0, null, () -> {
            throw new UnsupportedOperationException();
        });
    };
    DocumentMapperParser parser = new DocumentMapperParser(indexService.getIndexSettings(), indexService.mapperService(), indexService.getIndexAnalyzers(), indexService.xContentRegistry(), indexService.similarityService(), mapperRegistry, queryShardContext);
    DocumentMapper documentMapper = parser.parse("type", new CompressedXContent(XContentFactory.jsonBuilder().startObject().startObject("type").startObject(ExternalMetadataMapper.CONTENT_TYPE).endObject().startObject("properties").startObject("field").field("type", "external").endObject().endObject().endObject().endObject().string()));
    ParsedDocument doc = documentMapper.parse("test", "type", "1", XContentFactory.jsonBuilder().startObject().field("field", "1234").endObject().bytes());
    assertThat(doc.rootDoc().getField("field.bool"), notNullValue());
    assertThat(doc.rootDoc().getField("field.bool").stringValue(), is("T"));
    assertThat(doc.rootDoc().getField("field.point"), notNullValue());
    GeoPoint point = new GeoPoint().resetFromIndexableField(doc.rootDoc().getField("field.point"));
    assertThat(point.lat(), closeTo(42.0, 1e-5));
    assertThat(point.lon(), closeTo(51.0, 1e-5));
    assertThat(doc.rootDoc().getField("field.shape"), notNullValue());
    assertThat(doc.rootDoc().getField("field.field"), notNullValue());
    assertThat(doc.rootDoc().getField("field.field").stringValue(), is("foo"));
    assertThat(doc.rootDoc().getField(ExternalMetadataMapper.FIELD_NAME).stringValue(), is(ExternalMetadataMapper.FIELD_VALUE));
}
Also used : IndexService(org.elasticsearch.index.IndexService) GeoPoint(org.elasticsearch.common.geo.GeoPoint) Version(org.elasticsearch.Version) MapperRegistry(org.elasticsearch.indices.mapper.MapperRegistry) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) QueryShardContext(org.elasticsearch.index.query.QueryShardContext) Settings(org.elasticsearch.common.settings.Settings)

Example 9 with MapperRegistry

use of org.elasticsearch.indices.mapper.MapperRegistry in project elasticsearch by elastic.

the class Murmur3FieldMapperTests method setup.

@Before
public void setup() {
    indexService = createIndex("test");
    mapperRegistry = new MapperRegistry(Collections.singletonMap(Murmur3FieldMapper.CONTENT_TYPE, new Murmur3FieldMapper.TypeParser()), Collections.emptyMap());
    Supplier<QueryShardContext> queryShardContext = () -> {
        return indexService.newQueryShardContext(0, null, () -> {
            throw new UnsupportedOperationException();
        });
    };
    parser = new DocumentMapperParser(indexService.getIndexSettings(), indexService.mapperService(), indexService.getIndexAnalyzers(), indexService.xContentRegistry(), indexService.similarityService(), mapperRegistry, queryShardContext);
}
Also used : MapperRegistry(org.elasticsearch.indices.mapper.MapperRegistry) QueryShardContext(org.elasticsearch.index.query.QueryShardContext) DocumentMapperParser(org.elasticsearch.index.mapper.DocumentMapperParser) Before(org.junit.Before)

Example 10 with MapperRegistry

use of org.elasticsearch.indices.mapper.MapperRegistry in project elasticsearch by elastic.

the class FieldNamesFieldMapperTests method testSeesFieldsFromPlugins.

public void testSeesFieldsFromPlugins() throws IOException {
    IndexService indexService = createIndex("test");
    IndicesModule indicesModule = newTestIndicesModule(Collections.emptyMap(), Collections.singletonMap("_dummy", new DummyMetadataFieldMapper.TypeParser()));
    final MapperRegistry mapperRegistry = indicesModule.getMapperRegistry();
    Supplier<QueryShardContext> queryShardContext = () -> {
        return indexService.newQueryShardContext(0, null, () -> {
            throw new UnsupportedOperationException();
        });
    };
    MapperService mapperService = new MapperService(indexService.getIndexSettings(), indexService.getIndexAnalyzers(), indexService.xContentRegistry(), indexService.similarityService(), mapperRegistry, queryShardContext);
    DocumentMapperParser parser = new DocumentMapperParser(indexService.getIndexSettings(), mapperService, indexService.getIndexAnalyzers(), indexService.xContentRegistry(), indexService.similarityService(), mapperRegistry, queryShardContext);
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject().string();
    DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));
    ParsedDocument parsedDocument = mapper.parse("index", "type", "id", new BytesArray("{}"));
    IndexableField[] fields = parsedDocument.rootDoc().getFields(FieldNamesFieldMapper.NAME);
    boolean found = false;
    for (IndexableField f : fields) {
        if ("_dummy".equals(f.stringValue())) {
            found = true;
            break;
        }
    }
    assertTrue("Could not find the dummy field among " + Arrays.toString(fields), found);
}
Also used : IndicesModule(org.elasticsearch.indices.IndicesModule) BytesArray(org.elasticsearch.common.bytes.BytesArray) IndexService(org.elasticsearch.index.IndexService) IndexableField(org.apache.lucene.index.IndexableField) MapperRegistry(org.elasticsearch.indices.mapper.MapperRegistry) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) QueryShardContext(org.elasticsearch.index.query.QueryShardContext)

Aggregations

MapperRegistry (org.elasticsearch.indices.mapper.MapperRegistry)12 Settings (org.elasticsearch.common.settings.Settings)5 QueryShardContext (org.elasticsearch.index.query.QueryShardContext)5 Version (org.elasticsearch.Version)4 CompressedXContent (org.elasticsearch.common.compress.CompressedXContent)4 IndexService (org.elasticsearch.index.IndexService)4 HashMap (java.util.HashMap)2 IndexableField (org.apache.lucene.index.IndexableField)2 GeoPoint (org.elasticsearch.common.geo.GeoPoint)2 IndexAnalyzers (org.elasticsearch.index.analysis.IndexAnalyzers)2 MapperService (org.elasticsearch.index.mapper.MapperService)2 SimilarityService (org.elasticsearch.index.similarity.SimilarityService)2 BytesRef (org.apache.lucene.util.BytesRef)1 BytesArray (org.elasticsearch.common.bytes.BytesArray)1 IndexSettings (org.elasticsearch.index.IndexSettings)1 DocumentMapperParser (org.elasticsearch.index.mapper.DocumentMapperParser)1 IndicesModule (org.elasticsearch.indices.IndicesModule)1 Before (org.junit.Before)1