Search in sources :

Example 31 with DocumentMapper

use of org.elasticsearch.index.mapper.DocumentMapper in project elasticsearch by elastic.

the class PathMapperTests method testPathMapping.

public void testPathMapping() throws IOException {
    String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/path/test-mapping.json");
    DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse("person", new CompressedXContent(mapping));
    // test full name
    assertThat(docMapper.mappers().getMapper("first1"), nullValue());
    assertThat(docMapper.mappers().getMapper("name1.first1"), notNullValue());
    assertThat(docMapper.mappers().getMapper("last1"), nullValue());
    assertThat(docMapper.mappers().getMapper("i_last_1"), nullValue());
    assertThat(docMapper.mappers().getMapper("name1.last1"), notNullValue());
    assertThat(docMapper.mappers().getMapper("name1.i_last_1"), nullValue());
    assertThat(docMapper.mappers().getMapper("first2"), nullValue());
    assertThat(docMapper.mappers().getMapper("name2.first2"), notNullValue());
    assertThat(docMapper.mappers().getMapper("last2"), nullValue());
    assertThat(docMapper.mappers().getMapper("i_last_2"), nullValue());
    assertThat(docMapper.mappers().getMapper("name2.i_last_2"), nullValue());
    assertThat(docMapper.mappers().getMapper("name2.last2"), notNullValue());
}
Also used : DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent)

Example 32 with DocumentMapper

use of org.elasticsearch.index.mapper.DocumentMapper in project elasticsearch by elastic.

the class SimilarityTests method testResolveSimilaritiesFromMapping_IB.

public void testResolveSimilaritiesFromMapping_IB() throws IOException {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("field1").field("type", "text").field("similarity", "my_similarity").endObject().endObject().endObject().endObject().string();
    Settings indexSettings = Settings.builder().put("index.similarity.my_similarity.type", "IB").put("index.similarity.my_similarity.distribution", "spl").put("index.similarity.my_similarity.lambda", "ttf").put("index.similarity.my_similarity.normalization", "h2").put("index.similarity.my_similarity.normalization.h2.c", 3f).build();
    IndexService indexService = createIndex("foo", indexSettings);
    DocumentMapper documentMapper = indexService.mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
    assertThat(documentMapper.mappers().getMapper("field1").fieldType().similarity(), instanceOf(IBSimilarityProvider.class));
    IBSimilarity similarity = (IBSimilarity) documentMapper.mappers().getMapper("field1").fieldType().similarity().get();
    assertThat(similarity.getDistribution(), instanceOf(DistributionSPL.class));
    assertThat(similarity.getLambda(), instanceOf(LambdaTTF.class));
    assertThat(similarity.getNormalization(), instanceOf(NormalizationH2.class));
    assertThat(((NormalizationH2) similarity.getNormalization()).getC(), equalTo(3f));
}
Also used : IndexService(org.elasticsearch.index.IndexService) DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) DistributionSPL(org.apache.lucene.search.similarities.DistributionSPL) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) NormalizationH2(org.apache.lucene.search.similarities.NormalizationH2) IBSimilarity(org.apache.lucene.search.similarities.IBSimilarity) LambdaTTF(org.apache.lucene.search.similarities.LambdaTTF) Settings(org.elasticsearch.common.settings.Settings)

Example 33 with DocumentMapper

use of org.elasticsearch.index.mapper.DocumentMapper in project elasticsearch by elastic.

the class SimilarityTests method testResolveSimilaritiesFromMapping_LMDirichlet.

public void testResolveSimilaritiesFromMapping_LMDirichlet() throws IOException {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("field1").field("type", "text").field("similarity", "my_similarity").endObject().endObject().endObject().endObject().string();
    Settings indexSettings = Settings.builder().put("index.similarity.my_similarity.type", "LMDirichlet").put("index.similarity.my_similarity.mu", 3000f).build();
    IndexService indexService = createIndex("foo", indexSettings);
    DocumentMapper documentMapper = indexService.mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
    assertThat(documentMapper.mappers().getMapper("field1").fieldType().similarity(), instanceOf(LMDirichletSimilarityProvider.class));
    LMDirichletSimilarity similarity = (LMDirichletSimilarity) documentMapper.mappers().getMapper("field1").fieldType().similarity().get();
    assertThat(similarity.getMu(), equalTo(3000f));
}
Also used : IndexService(org.elasticsearch.index.IndexService) DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) LMDirichletSimilarity(org.apache.lucene.search.similarities.LMDirichletSimilarity) Settings(org.elasticsearch.common.settings.Settings)

Example 34 with DocumentMapper

use of org.elasticsearch.index.mapper.DocumentMapper in project elasticsearch by elastic.

the class SimilarityTests method testResolveSimilaritiesFromMapping_DFI.

public void testResolveSimilaritiesFromMapping_DFI() throws IOException {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("field1").field("type", "text").field("similarity", "my_similarity").endObject().endObject().endObject().endObject().string();
    Settings indexSettings = Settings.builder().put("index.similarity.my_similarity.type", "DFI").put("index.similarity.my_similarity.independence_measure", "chisquared").build();
    IndexService indexService = createIndex("foo", indexSettings);
    DocumentMapper documentMapper = indexService.mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
    MappedFieldType fieldType = documentMapper.mappers().getMapper("field1").fieldType();
    assertThat(fieldType.similarity(), instanceOf(DFISimilarityProvider.class));
    DFISimilarity similarity = (DFISimilarity) fieldType.similarity().get();
    assertThat(similarity.getIndependence(), instanceOf(IndependenceChiSquared.class));
}
Also used : IndexService(org.elasticsearch.index.IndexService) DFISimilarity(org.apache.lucene.search.similarities.DFISimilarity) IndependenceChiSquared(org.apache.lucene.search.similarities.IndependenceChiSquared) DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) MappedFieldType(org.elasticsearch.index.mapper.MappedFieldType) Settings(org.elasticsearch.common.settings.Settings)

Example 35 with DocumentMapper

use of org.elasticsearch.index.mapper.DocumentMapper in project elasticsearch by elastic.

the class ParentFieldLoadingIT method testChangingEagerParentFieldLoadingAtRuntime.

public void testChangingEagerParentFieldLoadingAtRuntime() throws Exception {
    assertAcked(prepareCreate("test").setSettings(indexSettings).addMapping("parent").addMapping("child", "_parent", "type=parent"));
    ensureGreen();
    client().prepareIndex("test", "parent", "1").setSource("{}", XContentType.JSON).get();
    client().prepareIndex("test", "child", "1").setParent("1").setSource("{}", XContentType.JSON).get();
    refresh();
    ClusterStatsResponse response = client().admin().cluster().prepareClusterStats().get();
    assertThat(response.getIndicesStats().getFieldData().getMemorySizeInBytes(), equalTo(0L));
    PutMappingResponse putMappingResponse = client().admin().indices().preparePutMapping("test").setType("child").setSource(childMapping(true)).setUpdateAllTypes(true).get();
    assertAcked(putMappingResponse);
    Index test = resolveIndex("test");
    assertBusy(new Runnable() {

        @Override
        public void run() {
            ClusterState clusterState = internalCluster().clusterService().state();
            ShardRouting shardRouting = clusterState.routingTable().index("test").shard(0).getShards().get(0);
            String nodeName = clusterState.getNodes().get(shardRouting.currentNodeId()).getName();
            boolean verified = false;
            IndicesService indicesService = internalCluster().getInstance(IndicesService.class, nodeName);
            IndexService indexService = indicesService.indexService(test);
            if (indexService != null) {
                MapperService mapperService = indexService.mapperService();
                DocumentMapper documentMapper = mapperService.documentMapper("child");
                if (documentMapper != null) {
                    verified = documentMapper.parentFieldMapper().fieldType().eagerGlobalOrdinals();
                }
            }
            assertTrue(verified);
        }
    });
    // Need to add a new doc otherwise the refresh doesn't trigger a new searcher
    // Because it ends up in its own segment, but isn't of type parent or child, this doc doesn't contribute to the size of the fielddata cache
    client().prepareIndex("test", "dummy", "dummy").setSource("{}", XContentType.JSON).get();
    refresh();
    response = client().admin().cluster().prepareClusterStats().get();
    assertThat(response.getIndicesStats().getFieldData().getMemorySizeInBytes(), greaterThan(0L));
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) IndexService(org.elasticsearch.index.IndexService) DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) IndicesService(org.elasticsearch.indices.IndicesService) Index(org.elasticsearch.index.Index) ClusterStatsResponse(org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse) PutMappingResponse(org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) MapperService(org.elasticsearch.index.mapper.MapperService)

Aggregations

DocumentMapper (org.elasticsearch.index.mapper.DocumentMapper)96 CompressedXContent (org.elasticsearch.common.compress.CompressedXContent)51 ParsedDocument (org.elasticsearch.index.mapper.ParsedDocument)35 IndexService (org.elasticsearch.index.IndexService)30 IndexableField (org.apache.lucene.index.IndexableField)20 BytesReference (org.elasticsearch.common.bytes.BytesReference)20 FieldMapper (org.elasticsearch.index.mapper.FieldMapper)16 Matchers.containsString (org.hamcrest.Matchers.containsString)15 Settings (org.elasticsearch.common.settings.Settings)14 MapperService (org.elasticsearch.index.mapper.MapperService)14 MappedFieldType (org.elasticsearch.index.mapper.MappedFieldType)12 DocumentMapperParser (org.elasticsearch.index.mapper.DocumentMapperParser)11 Test (org.junit.Test)11 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)10 Document (org.elasticsearch.index.mapper.ParseContext.Document)10 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)9 ArrayList (java.util.ArrayList)9 IOException (java.io.IOException)8 BytesArray (org.elasticsearch.common.bytes.BytesArray)8 Map (java.util.Map)7