Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrading analysis plugins fails #5034

Merged
merged 1 commit into from
Feb 7, 2014

Conversation

dadoonet
Copy link
Member

@dadoonet dadoonet commented Feb 6, 2014

When an analysis plugins provides default index settings using PreBuiltAnalyzerProviderFactory, PreBuiltTokenFilterFactoryFactory, PreBuiltTokenizerFactoryFactory or PreBuiltCharFilterFactoryFactory it fails when upgrading it with elasticsearch superior or equal to 0.90.5.

Related issue: #4936

Fix is needed in core. But, in the meantime, analysis plugins developers can fix that issue by overloading default prebuilt factories.

For example:

public class StempelAnalyzerProviderFactory extends PreBuiltAnalyzerProviderFactory {

    private final PreBuiltAnalyzerProvider analyzerProvider;

    public StempelAnalyzerProviderFactory(String name, AnalyzerScope scope, Analyzer analyzer) {
        super(name, scope, analyzer);
        analyzerProvider = new PreBuiltAnalyzerProvider(name, scope, analyzer);
    }

    @Override
    public AnalyzerProvider create(String name, Settings settings) {
        return analyzerProvider;
    }

    public Analyzer analyzer() {
        return analyzerProvider.get();
    }
}

And instead of:

    @Inject
    public PolishIndicesAnalysis(Settings settings, IndicesAnalysisService indicesAnalysisService) {
        super(settings);
        indicesAnalysisService.analyzerProviderFactories().put("polish", new PreBuiltAnalyzerProviderFactory("polish", AnalyzerScope.INDICES, new PolishAnalyzer(Lucene.ANALYZER_VERSION)));
    }

do

    @Inject
    public PolishIndicesAnalysis(Settings settings, IndicesAnalysisService indicesAnalysisService) {
        super(settings);
        indicesAnalysisService.analyzerProviderFactories().put("polish", new StempelAnalyzerProviderFactory("polish", AnalyzerScope.INDICES, new PolishAnalyzer(Lucene.ANALYZER_VERSION)));
    }

Closes #5030

@@ -401,4 +401,13 @@ public synchronized Analyzer getAnalyzer(Version version) {
return analyzer;
}

static public PreBuiltAnalyzers valueOf(String name, PreBuiltAnalyzers defaultAnalyzer) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we just delegate to valueOf and if it throws an exception we return the default? I don't think we should do the linear checks here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should also name it get or getOrDefault

@s1monw
Copy link
Contributor

s1monw commented Feb 6, 2014

It looks pretty cool though. now the hard part comes... can you write a test for it? We have the ability to set the index version in the settings so you could write a test that loads a dummy pluging that registers the prebuild stuff and create the index with a mapping and a different index version.

There are many utils for this like ElasticserachTestCase#randomVersion() or ElasticsearchTestCase#getPreviousVersion()...
To create the index you just need to do this:

Settings versionSettings = ImmutableSettings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, randomVersion()).build();

@dadoonet
Copy link
Member Author

dadoonet commented Feb 6, 2014

Great! I was wondering how to test it automatically! Going to look at this.

@dadoonet
Copy link
Member Author

dadoonet commented Feb 6, 2014

@s1monw Could you review it please? Tests fails without the patch and works when I apply the patch

@Inject
public DummyIndicesAnalysis(Settings settings, IndicesAnalysisService indicesAnalysisService) {
super(settings);
indicesAnalysisService.analyzerProviderFactories().put("dummy", new PreBuiltAnalyzerProviderFactory("dummy",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks awesome! exactly what I expected

can you also try to add prebuild TokenFitler and Tokenizer? just for kicks

@dadoonet
Copy link
Member Author

dadoonet commented Feb 6, 2014

@s1monw PR updated with test and headers updated. I think we are good now.

* See https://github.com/elasticsearch/elasticsearch/issues/5030
*/
@Test
public void testThatPluginAnalyzersCanBeUpdated() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm why did you remove the mapping from here? I think that was a good change?
you should add the settings from from public Settings indexSettings() are only used if you use prepareCreate so you should add the settings to the versionSettings below.

other than that it looks awesome

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I ran the test without the patch and without the mapping and it was failing. So I guess that this analyzer is set by default when creating the index. So we don't need to set it on a specific field to reproduce the issue.

That said I can add the mapping again.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About indexSettings(), this is true. I added to versionSettings and I have now an error which I need to fix. Will push a new update soon.

When an analysis plugins provides default index settings using `PreBuiltAnalyzerProviderFactory`,  `PreBuiltTokenFilterFactoryFactory` or `PreBuiltTokenizerFactoryFactory` it fails when upgrading it with elasticsearch superior or equal to 0.90.5.

Related issue: elastic#4936

Fix is needed in core. But, in the meantime, analysis plugins developers can fix that issue by overloading default prebuilt factories.

For example:

```java
public class StempelAnalyzerProviderFactory extends PreBuiltAnalyzerProviderFactory {

    private final PreBuiltAnalyzerProvider analyzerProvider;

    public StempelAnalyzerProviderFactory(String name, AnalyzerScope scope, Analyzer analyzer) {
        super(name, scope, analyzer);
        analyzerProvider = new PreBuiltAnalyzerProvider(name, scope, analyzer);
    }

    @OverRide
    public AnalyzerProvider create(String name, Settings settings) {
        return analyzerProvider;
    }

    public Analyzer analyzer() {
        return analyzerProvider.get();
    }
}
```

And instead of:

```java
    @Inject
    public PolishIndicesAnalysis(Settings settings, IndicesAnalysisService indicesAnalysisService) {
        super(settings);
        indicesAnalysisService.analyzerProviderFactories().put("polish", new PreBuiltAnalyzerProviderFactory("polish", AnalyzerScope.INDICES, new PolishAnalyzer(Lucene.ANALYZER_VERSION)));
    }
```

do

```java
    @Inject
    public PolishIndicesAnalysis(Settings settings, IndicesAnalysisService indicesAnalysisService) {
        super(settings);
        indicesAnalysisService.analyzerProviderFactories().put("polish", new StempelAnalyzerProviderFactory("polish", AnalyzerScope.INDICES, new PolishAnalyzer(Lucene.ANALYZER_VERSION)));
    }
```

Closes elastic#5030
@s1monw
Copy link
Contributor

s1monw commented Feb 7, 2014

David this looks great +1 to push

@dadoonet dadoonet merged commit 619fec2 into elastic:1.0 Feb 7, 2014
@dadoonet dadoonet deleted the issue/5030-prebuilt-analysis branch February 7, 2014 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants