use of org.elasticsearch.index.mapper.DocumentMapper in project elasticsearch by elastic.
the class SimilarityTests method testResolveSimilaritiesFromMapping_bm25.
public void testResolveSimilaritiesFromMapping_bm25() 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", "BM25").put("index.similarity.my_similarity.k1", 2.0f).put("index.similarity.my_similarity.b", 0.5f).put("index.similarity.my_similarity.discount_overlaps", false).build();
IndexService indexService = createIndex("foo", indexSettings);
DocumentMapper documentMapper = indexService.mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
assertThat(documentMapper.mappers().getMapper("field1").fieldType().similarity(), instanceOf(BM25SimilarityProvider.class));
BM25Similarity similarity = (BM25Similarity) documentMapper.mappers().getMapper("field1").fieldType().similarity().get();
assertThat(similarity.getK1(), equalTo(2.0f));
assertThat(similarity.getB(), equalTo(0.5f));
assertThat(similarity.getDiscountOverlaps(), equalTo(false));
}
use of org.elasticsearch.index.mapper.DocumentMapper in project elasticsearch by elastic.
the class SimilarityTests method testResolveSimilaritiesFromMapping_DFR.
public void testResolveSimilaritiesFromMapping_DFR() 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", "DFR").put("index.similarity.my_similarity.basic_model", "g").put("index.similarity.my_similarity.after_effect", "l").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(DFRSimilarityProvider.class));
DFRSimilarity similarity = (DFRSimilarity) documentMapper.mappers().getMapper("field1").fieldType().similarity().get();
assertThat(similarity.getBasicModel(), instanceOf(BasicModelG.class));
assertThat(similarity.getAfterEffect(), instanceOf(AfterEffectL.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 testSimilarityDefaultBackCompat.
public void testSimilarityDefaultBackCompat() throws IOException {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("field1").field("similarity", "default").field("type", "text").endObject().endObject().endObject().endObject().string();
Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.V_2_2_0)).build();
DocumentMapperParser parser = createIndex("test_v2.x", settings).mapperService().documentMapperParser();
DocumentMapper documentMapper = parser.parse("type", new CompressedXContent(mapping));
assertThat(documentMapper.mappers().getMapper("field1").fieldType().similarity(), instanceOf(ClassicSimilarityProvider.class));
assertThat(documentMapper.mappers().getMapper("field1").fieldType().similarity().name(), equalTo("classic"));
parser = createIndex("test_v3.x").mapperService().documentMapperParser();
try {
parser.parse("type", new CompressedXContent(mapping));
fail("Expected MappingParsingException");
} catch (MapperParsingException e) {
assertThat(e.getMessage(), equalTo("Unknown Similarity type [default] for field [field1]"));
}
}
use of org.elasticsearch.index.mapper.DocumentMapper in project elasticsearch by elastic.
the class SimilarityTests method testResolveSimilaritiesFromMapping_LMJelinekMercer.
public void testResolveSimilaritiesFromMapping_LMJelinekMercer() 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", "LMJelinekMercer").put("index.similarity.my_similarity.lambda", 0.7f).build();
IndexService indexService = createIndex("foo", indexSettings);
DocumentMapper documentMapper = indexService.mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
assertThat(documentMapper.mappers().getMapper("field1").fieldType().similarity(), instanceOf(LMJelinekMercerSimilarityProvider.class));
LMJelinekMercerSimilarity similarity = (LMJelinekMercerSimilarity) documentMapper.mappers().getMapper("field1").fieldType().similarity().get();
assertThat(similarity.getLambda(), equalTo(0.7f));
}
use of org.elasticsearch.index.mapper.DocumentMapper in project elasticsearch by elastic.
the class ParentToChildrenAggregatorTests method mapperServiceMock.
@Override
protected MapperService mapperServiceMock() {
MapperService mapperService = mock(MapperService.class);
DocumentMapper childDocMapper = mock(DocumentMapper.class);
DocumentMapper parentDocMapper = mock(DocumentMapper.class);
ParentFieldMapper parentFieldMapper = createParentFieldMapper();
when(childDocMapper.parentFieldMapper()).thenReturn(parentFieldMapper);
when(parentDocMapper.parentFieldMapper()).thenReturn(parentFieldMapper);
when(mapperService.documentMapper(CHILD_TYPE)).thenReturn(childDocMapper);
when(mapperService.documentMapper(PARENT_TYPE)).thenReturn(parentDocMapper);
when(mapperService.docMappers(false)).thenReturn(Arrays.asList(new DocumentMapper[] { childDocMapper, parentDocMapper }));
when(parentDocMapper.typeFilter()).thenReturn(new TypeFieldMapper.TypesQuery(new BytesRef(PARENT_TYPE)));
when(childDocMapper.typeFilter()).thenReturn(new TypeFieldMapper.TypesQuery(new BytesRef(CHILD_TYPE)));
return mapperService;
}
Aggregations