Search in sources :

Example 1 with CompletionFieldType

use of org.opensearch.index.mapper.CompletionFieldMapper.CompletionFieldType in project OpenSearch by opensearch-project.

the class CategoryContextMappingTests method testUnknownQueryContextParsing.

public void testUnknownQueryContextParsing() throws Exception {
    XContentBuilder mapping = jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("completion").field("type", "completion").startArray("contexts").startObject().field("name", "ctx").field("type", "category").endObject().startObject().field("name", "type").field("type", "category").endObject().endArray().endObject().endObject().endObject().endObject();
    MapperService mapperService = createIndex("test", Settings.EMPTY, "type1", mapping).mapperService();
    CompletionFieldType completionFieldType = (CompletionFieldType) mapperService.fieldType("completion");
    Exception e = expectThrows(IllegalArgumentException.class, () -> completionFieldType.getContextMappings().get("brand"));
    assertEquals("Unknown context name [brand], must be one of [ctx, type]", e.getMessage());
}
Also used : CompletionFieldType(org.opensearch.index.mapper.CompletionFieldMapper.CompletionFieldType) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) MapperService(org.opensearch.index.mapper.MapperService) MapperParsingException(org.opensearch.index.mapper.MapperParsingException) XContentParseException(org.opensearch.common.xcontent.XContentParseException)

Example 2 with CompletionFieldType

use of org.opensearch.index.mapper.CompletionFieldMapper.CompletionFieldType in project OpenSearch by opensearch-project.

the class CompletionSuggesterBuilderTests method mockFieldType.

@Override
protected MappedFieldType mockFieldType(String fieldName, boolean analyzerSet) {
    if (analyzerSet == false) {
        CompletionFieldType completionFieldType = new CompletionFieldType(fieldName, null, Collections.emptyMap());
        completionFieldType.setContextMappings(new ContextMappings(contextMappings));
        return completionFieldType;
    }
    CompletionFieldType completionFieldType = new CompletionFieldType(fieldName, new NamedAnalyzer("fieldSearchAnalyzer", AnalyzerScope.INDEX, new SimpleAnalyzer()), Collections.emptyMap());
    completionFieldType.setContextMappings(new ContextMappings(contextMappings));
    return completionFieldType;
}
Also used : NamedAnalyzer(org.opensearch.index.analysis.NamedAnalyzer) SimpleAnalyzer(org.apache.lucene.analysis.core.SimpleAnalyzer) CompletionFieldType(org.opensearch.index.mapper.CompletionFieldMapper.CompletionFieldType) ContextMappings(org.opensearch.search.suggest.completion.context.ContextMappings)

Aggregations

CompletionFieldType (org.opensearch.index.mapper.CompletionFieldMapper.CompletionFieldType)2 SimpleAnalyzer (org.apache.lucene.analysis.core.SimpleAnalyzer)1 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)1 XContentParseException (org.opensearch.common.xcontent.XContentParseException)1 NamedAnalyzer (org.opensearch.index.analysis.NamedAnalyzer)1 MapperParsingException (org.opensearch.index.mapper.MapperParsingException)1 MapperService (org.opensearch.index.mapper.MapperService)1 ContextMappings (org.opensearch.search.suggest.completion.context.ContextMappings)1