use of org.elasticsearch.common.compress.CompressedXContent in project elasticsearch by elastic.
the class CompletionFieldMapperTests method testParsingFull.
public void testParsingFull() throws Exception {
String mapping = jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("completion").field("type", "completion").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", XContentFactory.jsonBuilder().startObject().startArray("completion").startObject().field("input", "suggestion1").field("weight", 3).endObject().startObject().field("input", "suggestion2").field("weight", 4).endObject().startObject().field("input", "suggestion3").field("weight", 5).endObject().endArray().endObject().bytes());
IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name());
assertSuggestFields(fields, 3);
}
use of org.elasticsearch.common.compress.CompressedXContent in project elasticsearch by elastic.
the class CompletionFieldMapperTests method testCompletionAnalyzerSettings.
public void testCompletionAnalyzerSettings() throws Exception {
String mapping = jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("completion").field("type", "completion").field("analyzer", "simple").field("search_analyzer", "standard").field("preserve_separators", false).field("preserve_position_increments", true).endObject().endObject().endObject().endObject().string();
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type1", new CompressedXContent(mapping));
FieldMapper fieldMapper = defaultMapper.mappers().getMapper("completion");
assertThat(fieldMapper, instanceOf(CompletionFieldMapper.class));
MappedFieldType completionFieldType = fieldMapper.fieldType();
NamedAnalyzer indexAnalyzer = completionFieldType.indexAnalyzer();
assertThat(indexAnalyzer.name(), equalTo("simple"));
assertThat(indexAnalyzer.analyzer(), instanceOf(CompletionAnalyzer.class));
CompletionAnalyzer analyzer = (CompletionAnalyzer) indexAnalyzer.analyzer();
assertThat(analyzer.preservePositionIncrements(), equalTo(true));
assertThat(analyzer.preserveSep(), equalTo(false));
NamedAnalyzer searchAnalyzer = completionFieldType.searchAnalyzer();
assertThat(searchAnalyzer.name(), equalTo("standard"));
assertThat(searchAnalyzer.analyzer(), instanceOf(CompletionAnalyzer.class));
analyzer = (CompletionAnalyzer) searchAnalyzer.analyzer();
assertThat(analyzer.preservePositionIncrements(), equalTo(true));
assertThat(analyzer.preserveSep(), equalTo(false));
}
use of org.elasticsearch.common.compress.CompressedXContent in project elasticsearch by elastic.
the class CompletionFieldMapperTests method testEmptyName.
public void testEmptyName() throws IOException {
IndexService indexService = createIndex("test");
DocumentMapperParser parser = indexService.mapperService().documentMapperParser();
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("").field("type", "completion").endObject().endObject().endObject().endObject().string();
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> parser.parse("type", new CompressedXContent(mapping)));
assertThat(e.getMessage(), containsString("name cannot be empty string"));
}
use of org.elasticsearch.common.compress.CompressedXContent in project elasticsearch by elastic.
the class CompletionFieldMapperTests method testParsingWithWeight.
public void testParsingWithWeight() throws Exception {
String mapping = jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("completion").field("type", "completion").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", XContentFactory.jsonBuilder().startObject().startObject("completion").field("input", "suggestion").field("weight", 2).endObject().endObject().bytes());
IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name());
assertSuggestFields(fields, 1);
}
use of org.elasticsearch.common.compress.CompressedXContent in project elasticsearch by elastic.
the class CompletionFieldMapperTests method testPrefixQueryType.
public void testPrefixQueryType() throws Exception {
String mapping = jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("completion").field("type", "completion").endObject().endObject().endObject().endObject().string();
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type1", new CompressedXContent(mapping));
FieldMapper fieldMapper = defaultMapper.mappers().getMapper("completion");
CompletionFieldMapper completionFieldMapper = (CompletionFieldMapper) fieldMapper;
Query prefixQuery = completionFieldMapper.fieldType().prefixQuery(new BytesRef("co"));
assertThat(prefixQuery, instanceOf(PrefixCompletionQuery.class));
}
Aggregations