org.elasticsearch.index.analysis.AnalysisService Java Examples

The following examples show how to use org.elasticsearch.index.analysis.AnalysisService. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BaseformTokenFilterTests.java    From elasticsearch-analysis-baseform with Apache License 2.0 6 votes vote down vote up
@Test
public void testThree() throws IOException {

    String source = "wurde zum tollen gemacht";

    String[] expected = {
            "wurde",
            "werden",
            "zum",
            "zum",
            "tollen",
            "tollen",
            "gemacht",
            "machen"
    };
    AnalysisService analysisService = MapperTestUtils.analysisService();
    TokenFilterFactory tokenFilter = analysisService.tokenFilter("baseform");
    Tokenizer tokenizer = analysisService.tokenizer("standard").create();
    tokenizer.setReader(new StringReader(source));
    assertSimpleTSOutput(tokenFilter.create(tokenizer), expected);
}
 
Example #2
Source File: BaseformTokenFilterTests.java    From elasticsearch-analysis-baseform with Apache License 2.0 6 votes vote down vote up
@Test
public void testTwo() throws IOException {

    String source = "Das sind Autos, die Nudeln transportieren.";

    String[] expected = {
            "Das",
            "Das",
            "sind",
            "sind",
            "Autos",
            "Auto",
            "die",
            "der",
            "Nudeln",
            "Nudel",
            "transportieren",
            "transportieren"
    };
    AnalysisService analysisService = MapperTestUtils.analysisService();
    TokenFilterFactory tokenFilter = analysisService.tokenFilter("baseform");
    Tokenizer tokenizer = analysisService.tokenizer("standard").create();
    tokenizer.setReader(new StringReader(source));
    assertSimpleTSOutput(tokenFilter.create(tokenizer), expected);
}
 
Example #3
Source File: MetaDataIndexUpgradeService.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
/**
 * Checks the mappings for compatibility with the current version
 */
private void checkMappingsCompatibility(IndexMetaData indexMetaData) {
    Index index = new Index(indexMetaData.getIndex());
    Settings settings = indexMetaData.getSettings();
    try {
        SimilarityLookupService similarityLookupService = new SimilarityLookupService(index, settings);
        // We cannot instantiate real analysis server at this point because the node might not have
        // been started yet. However, we don't really need real analyzers at this stage - so we can fake it
        try (AnalysisService analysisService = new FakeAnalysisService(index, settings)) {
            try (MapperService mapperService = new MapperService(index, settings, analysisService, similarityLookupService,
                    scriptService, mapperRegistry, dynamicArrayFieldMapperBuilderFactoryProvider)) {
                for (ObjectCursor<MappingMetaData> cursor : indexMetaData.getMappings().values()) {
                    MappingMetaData mappingMetaData = cursor.value;
                    mapperService.merge(mappingMetaData.type(), mappingMetaData.source(), MapperService.MergeReason.MAPPING_RECOVERY, false);
                }
            }
        }
    } catch (Exception ex) {
        // Wrap the inner exception so we have the index name in the exception message
        throw new IllegalStateException("unable to upgrade the mappings for the index [" + indexMetaData.getIndex() + "], reason: [" + ex.getMessage() + "]", ex);
    }
}
 
Example #4
Source File: IndexQueryParserService.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Inject
public IndexQueryParserService(Index index, IndexSettingsService indexSettingsService,
                               IndicesQueriesRegistry indicesQueriesRegistry,
                               ScriptService scriptService, AnalysisService analysisService,
                               MapperService mapperService, IndexCache indexCache, IndexFieldDataService fieldDataService,
                               BitsetFilterCache bitsetFilterCache,
                               @Nullable SimilarityService similarityService) {
    super(index, indexSettingsService.getSettings());
    this.indexSettingsService = indexSettingsService;
    this.scriptService = scriptService;
    this.analysisService = analysisService;
    this.mapperService = mapperService;
    this.similarityService = similarityService;
    this.indexCache = indexCache;
    this.fieldDataService = fieldDataService;
    this.bitsetFilterCache = bitsetFilterCache;

    Settings indexSettings = indexSettingsService.getSettings();
    this.defaultField = indexSettings.get(DEFAULT_FIELD, AllFieldMapper.NAME);
    this.queryStringLenient = indexSettings.getAsBoolean(QUERY_STRING_LENIENT, false);
    this.parseFieldMatcher = new ParseFieldMatcher(indexSettings);
    this.defaultAllowUnmappedFields = indexSettings.getAsBoolean(ALLOW_UNMAPPED, true);
    this.indicesQueriesRegistry = indicesQueriesRegistry;
}
 
Example #5
Source File: IkESPluginTest.java    From es-ik with Apache License 2.0 6 votes vote down vote up
@Test
public void testDefaultsIcuAnalysis() {
    Index index = new Index("test");

    Settings settings = ImmutableSettings.settingsBuilder()
            .put("path.home", "none")
            .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
            .build();

    Injector parentInjector = new ModulesBuilder().add(new SettingsModule(ImmutableSettings.EMPTY), new EnvironmentModule(new Environment(settings)), new IndicesAnalysisModule()).createInjector();
    Injector injector = new ModulesBuilder().add(
            new IndexSettingsModule(index, settings),
            new IndexNameModule(index),
            new AnalysisModule(ImmutableSettings.EMPTY, parentInjector.getInstance(IndicesAnalysisService.class)).addProcessor(new IKAnalysisBinderProcessor()))
            .createChildInjector(parentInjector);

    AnalysisService analysisService = injector.getInstance(AnalysisService.class);

    TokenizerFactory tokenizerFactory = analysisService.tokenizer("ik_tokenizer");
    MatcherAssert.assertThat(tokenizerFactory, instanceOf(IKTokenizerFactory.class));


}
 
Example #6
Source File: MapperTestUtils.java    From elasticsearch-analysis-baseform with Apache License 2.0 5 votes vote down vote up
public static AnalysisService analysisService(Settings settings) {
    Settings newSettings = Settings.settingsBuilder()
            .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
            .put("path.home", System.getProperty("path.home"))
            .put("client.type", "node")
            .put(settings)
            .build();
    return newMapperService(newSettings, null).analysisService();
}
 
Example #7
Source File: MapperTestUtils.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private static AnalysisService newAnalysisService(Settings indexSettings) {
    Injector parentInjector = new ModulesBuilder().add(new SettingsModule(indexSettings), new EnvironmentModule(new Environment(indexSettings))).createInjector();
    Index index = new Index("test");
    Injector injector = new ModulesBuilder().add(
        new IndexSettingsModule(index, indexSettings),
        new IndexNameModule(index),
        new AnalysisModule(indexSettings, parentInjector.getInstance(IndicesAnalysisService.class))).createChildInjector(parentInjector);

    return injector.getInstance(AnalysisService.class);
}
 
Example #8
Source File: Mapper.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public ParserContext(String type, AnalysisService analysisService, SimilarityLookupService similarityLookupService,
                     MapperService mapperService, Map<String, TypeParser> typeParsers,
                     Version indexVersionCreated, ParseFieldMatcher parseFieldMatcher) {
    this.type = type;
    this.analysisService = analysisService;
    this.similarityLookupService = similarityLookupService;
    this.mapperService = mapperService;
    this.typeParsers = typeParsers;
    this.indexVersionCreated = indexVersionCreated;
    this.parseFieldMatcher = parseFieldMatcher;
}
 
Example #9
Source File: MapperService.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public MapperService(Index index, Settings indexSettings, AnalysisService analysisService,
                     SimilarityLookupService similarityLookupService,
                     ScriptService scriptService, MapperRegistry mapperRegistry,
                     DynamicArrayFieldMapperBuilderFactoryProvider dynamicArrayFieldMapperBuilderFactoryProvider) {
    this(index, new IndexSettingsService(index, indexSettings), analysisService, similarityLookupService, scriptService,
        mapperRegistry, dynamicArrayFieldMapperBuilderFactoryProvider);
}
 
Example #10
Source File: MapperTestUtils.java    From elasticsearch-analysis-baseform with Apache License 2.0 5 votes vote down vote up
public static AnalysisService newAnalysisService(Settings indexSettings) {
    Injector parentInjector = new ModulesBuilder().add(new SettingsModule(indexSettings),
            new EnvironmentModule(new Environment(indexSettings))).createInjector();
    Index index = new Index("test");
    Injector injector = new ModulesBuilder().add(
            new IndexSettingsModule(index, indexSettings),
            new IndexNameModule(index),
            new AnalysisModule(indexSettings, parentInjector.getInstance(IndicesAnalysisService.class))).createChildInjector(parentInjector);

    return injector.getInstance(AnalysisService.class);
}
 
Example #11
Source File: MapperTestUtils.java    From elasticsearch-analysis-baseform with Apache License 2.0 5 votes vote down vote up
public static MapperService newMapperService(Settings settings, Client client) {
    Settings indexSettings = Settings.builder()
            .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
            .put("path.home", System.getProperty("path.home"))
            .put("client.type", "node")
            .put(settings)
            .build();
    Index index = new Index("test");
    Injector parentInjector = new ModulesBuilder()
            .add(new SettingsModule(indexSettings),
            new EnvironmentModule(new Environment(indexSettings)))
            .createInjector();
    AnalysisModule analysisModule = new AnalysisModule(indexSettings,
            parentInjector.getInstance(IndicesAnalysisService.class));
    new AnalysisBaseformPlugin(settings).onModule(analysisModule);
    Injector injector = new ModulesBuilder().add(new IndexSettingsModule(index, indexSettings),
            new IndexNameModule(index),
            analysisModule)
            .createChildInjector(parentInjector);
    AnalysisService analysisService = injector.getInstance(AnalysisService.class);
    SimilarityLookupService similarityLookupService = new SimilarityLookupService(index, indexSettings);
    Map<String, Mapper.TypeParser> mappers = registerBuiltInMappers();
    Map<String, MetadataFieldMapper.TypeParser> metadataMappers = registerBuiltInMetadataMappers();
    MapperRegistry mapperRegistry = new MapperRegistry(mappers, metadataMappers);
    return new MapperService(new Index("test"),
            indexSettings,
            analysisService,
            similarityLookupService,
            null,
            mapperRegistry);
}
 
Example #12
Source File: MapperTestUtils.java    From elasticsearch-analysis-baseform with Apache License 2.0 5 votes vote down vote up
public static AnalysisService analysisService() {
    Settings settings = Settings.settingsBuilder()
            .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
            .put("path.home", System.getProperty("path.home"))
            .put("client.type", "node")
            .build();
    return newMapperService(settings, null).analysisService();
}
 
Example #13
Source File: DocumentMapperParser.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public DocumentMapperParser(Settings indexSettings, MapperService mapperService, AnalysisService analysisService,
                            SimilarityLookupService similarityLookupService, ScriptService scriptService,
                            MapperRegistry mapperRegistry,
                            @Nullable DynamicArrayFieldMapperBuilderFactory dynamicArrayFieldMapperBuilderFactory) {
    this.dynamicArrayFieldMapperBuilderFactory = dynamicArrayFieldMapperBuilderFactory;
    this.parseFieldMatcher = new ParseFieldMatcher(indexSettings);
    this.scriptService = scriptService;
    this.mapperService = mapperService;
    this.analysisService = analysisService;
    this.similarityLookupService = similarityLookupService;
    this.typeParsers = mapperRegistry.getMapperParsers();
    this.rootTypeParsers = mapperRegistry.getMetadataMapperParsers();
    indexVersionCreated = Version.indexCreated(indexSettings);
}
 
Example #14
Source File: MapperTestUtils.java    From elasticsearch-analysis-baseform with Apache License 2.0 5 votes vote down vote up
public static AnalysisService analysisService(String resource) {
    Settings settings = Settings.settingsBuilder()
            .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
            .put("path.home", System.getProperty("path.home"))
            .put("client.type", "node")
            .loadFromStream(resource, MapperTestUtils.class.getResourceAsStream(resource))
            .build();
    return newMapperService(settings, null).analysisService();
}
 
Example #15
Source File: IndexService.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Inject
public IndexService(Injector injector, Index index, NodeEnvironment nodeEnv,
                    AnalysisService analysisService, MapperService mapperService, IndexQueryParserService queryParserService,
                    SimilarityService similarityService, IndexAliasesService aliasesService, IndexCache indexCache,
                    IndexSettingsService settingsService,
                    IndexFieldDataService indexFieldData, BitsetFilterCache bitSetFilterCache, IndicesService indicesServices) {

    super(index, settingsService.getSettings());
    this.injector = injector;
    this.analysisService = analysisService;
    this.mapperService = mapperService;
    this.queryParserService = queryParserService;
    this.similarityService = similarityService;
    this.aliasesService = aliasesService;
    this.indexCache = indexCache;
    this.indexFieldData = indexFieldData;
    this.settingsService = settingsService;
    this.bitsetFilterCache = bitSetFilterCache;

    this.pluginsService = injector.getInstance(PluginsService.class);
    this.indicesServices = indicesServices;
    this.indicesLifecycle = (InternalIndicesLifecycle) injector.getInstance(IndicesLifecycle.class);

    // inject workarounds for cyclic dep
    indexFieldData.setListener(new FieldDataCacheListener(this));
    bitSetFilterCache.setListener(new BitsetCacheListener(this));
    this.nodeEnv = nodeEnv;
}
 
Example #16
Source File: BaseformTokenFilterTests.java    From elasticsearch-analysis-baseform with Apache License 2.0 5 votes vote down vote up
@Test
public void testOne() throws IOException {

    String source = "Die Jahresfeier der Rechtsanwaltskanzleien auf dem Donaudampfschiff hat viel Ökosteuer gekostet";

    String[] expected = {
            "Die",
            "Die",
            "Jahresfeier",
            "Jahresfeier",
            "der",
            "der",
            "Rechtsanwaltskanzleien",
            "Rechtsanwaltskanzlei",
            "auf",
            "auf",
            "dem",
            "der",
            "Donaudampfschiff",
            "Donaudampfschiff",
            "hat",
            "haben",
            "viel",
            "viel",
            "Ökosteuer",
            "Ökosteuer",
            "gekostet",
            "kosten"
    };
    AnalysisService analysisService = MapperTestUtils.analysisService();
    TokenFilterFactory tokenFilter = analysisService.tokenFilter("baseform");
    Tokenizer tokenizer = analysisService.tokenizer("standard").create();
    tokenizer.setReader(new StringReader(source));
    assertSimpleTSOutput(tokenFilter.create(tokenizer), expected);
}
 
Example #17
Source File: GermanBaseformTokenFilterTests.java    From elasticsearch-analysis-baseform with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void create() throws IOException {
    Settings settings = Settings.settingsBuilder()
            .loadFromSource(copyToStringFromClasspath(("/org/xbib/elasticsearch/index/analysis/baseform_de.json")))
            .build();
    AnalysisService analysisService = MapperTestUtils.analysisService(settings);
    analyzer = analysisService.analyzer("baseform");
}
 
Example #18
Source File: MapperService.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public AnalysisService analysisService() {
    return this.analysisService;
}
 
Example #19
Source File: Mapper.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public AnalysisService analysisService() {
    return analysisService;
}
 
Example #20
Source File: PercolateContext.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public AnalysisService analysisService() {
    return indexService.analysisService();
}
 
Example #21
Source File: MapperService.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Inject
public MapperService(Index index, IndexSettingsService indexSettingsService, AnalysisService analysisService,
                     SimilarityLookupService similarityLookupService,
                     ScriptService scriptService, MapperRegistry mapperRegistry,
                     DynamicArrayFieldMapperBuilderFactoryProvider dynamicArrayFieldMapperBuilderFactoryProvider) {
    super(index, indexSettingsService.getSettings());
    this.indexSettings = indexSettingsService.getSettings();
    this.indexSettingsService = indexSettingsService;
    this.analysisService = analysisService;
    this.mapperRegistry = mapperRegistry;
    this.fieldTypes = new FieldTypeLookup();
    this.documentParser = new DocumentMapperParser(indexSettings, this, analysisService, similarityLookupService,
            scriptService, mapperRegistry, dynamicArrayFieldMapperBuilderFactoryProvider.get());
    this.indexAnalyzer = new MapperAnalyzerWrapper(analysisService.defaultIndexAnalyzer(), INDEX_ANALYZER_EXTRACTOR);
    this.searchAnalyzer = new MapperAnalyzerWrapper(analysisService.defaultSearchAnalyzer(), SEARCH_ANALYZER_EXTRACTOR);
    this.searchQuoteAnalyzer = new MapperAnalyzerWrapper(analysisService.defaultSearchQuoteAnalyzer(), SEARCH_QUOTE_ANALYZER_EXTRACTOR);

    this.dynamic = this.indexSettings.getAsBoolean(INDEX_MAPPER_DYNAMIC_SETTING, INDEX_MAPPER_DYNAMIC_DEFAULT);
    defaultPercolatorMappingSource = "{\n" +
        "\"_default_\":{\n" +
        "\"properties\" : {\n" +
        "\"query\" : {\n" +
        "\"type\" : \"object\",\n" +
        "\"enabled\" : false\n" +
        "}\n" +
        "}\n" +
        "}\n" +
        "}";
    if (index.getName().equals(ScriptService.SCRIPT_INDEX)){
        defaultMappingSource =  "{" +
            "\"_default_\": {" +
            "\"properties\": {" +
            "\"script\": { \"enabled\": false }," +
            "\"template\": { \"enabled\": false }" +
            "}" +
            "}" +
            "}";
    } else {
        defaultMappingSource = "{\"_default_\":{}}";
    }

    if (logger.isTraceEnabled()) {
        logger.trace("using dynamic[{}], default mapping source[{}], default percolator mapping source[{}]", dynamic, defaultMappingSource, defaultPercolatorMappingSource);
    } else if (logger.isDebugEnabled()) {
        logger.debug("using dynamic[{}]", dynamic);
    }
}
 
Example #22
Source File: ParseContext.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public AnalysisService analysisService() {
    return docMapperParser.analysisService;
}
 
Example #23
Source File: ParseContext.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public AnalysisService analysisService() {
    return in.analysisService();
}
 
Example #24
Source File: IndexService.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public AnalysisService analysisService() {
    return this.analysisService;
}
 
Example #25
Source File: QueryParseContext.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public AnalysisService analysisService() {
    return indexQueryParser.analysisService;
}
 
Example #26
Source File: DefaultSearchContext.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public AnalysisService analysisService() {
    return indexService.analysisService();
}
 
Example #27
Source File: FilteredSearchContext.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public AnalysisService analysisService() {
    return in.analysisService();
}
 
Example #28
Source File: ParseContext.java    From Elasticsearch with Apache License 2.0 votes vote down vote up
public abstract AnalysisService analysisService(); 
Example #29
Source File: SearchContext.java    From Elasticsearch with Apache License 2.0 votes vote down vote up
public abstract AnalysisService analysisService();