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());
}
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));
}
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));
}
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));
}
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));
}
Aggregations