# Defining a new analyzer provider forces pakcage name of the provider to begin with org.elasticsearch

**URL:** <https://discuss.elastic.co/t/defining-a-new-analyzer-provider-forces-pakcage-name-of-the-provider-to-begin-with-org-elasticsearch/3710>\
**Category:** Elasticsearch\
**Created:** [December 29, 2010, 2:55pm UTC](https://discuss.elastic.co/t/defining-a-new-analyzer-provider-forces-pakcage-name-of-the-provider-to-begin-with-org-elasticsearch/3710 "2010-12-29T14:55:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![erez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/erez/32/3182_2.png) [@erez](https://discuss.elastic.co/u/erez)\
**Post date:** [December 29, 2010, 2:55pm UTC](https://discuss.elastic.co/t/defining-a-new-analyzer-provider-forces-pakcage-name-of-the-provider-to-begin-with-org-elasticsearch/3710/1 "2010-12-29T14:55:59Z")

</div>

My elasticsearch properties define my own type:  
index.analysis.analyzer.my\_analyzer.type=org.me.index.analysis.MyWonderfulAnalyzerProvider  
When I run it I get a  
org.elasticsearch.common.settings.SettingsException:  
Caused by: org.elasticsearch.common.settings.SettingsException:  
Component [org.me.index.analysis.MyWonderfulAnalyzerProvider] does not  
start with prefix [org.elasticsearch]  
at  
org.elasticsearch.common.settings.ImmutableSettings.getComponentSettings(ImmutableSettings.java:  
91)  
at  
org.elasticsearch.common.settings.ImmutableSettings.getComponentSettings(ImmutableSettings.java:  
85)  
at  
org.elasticsearch.index.AbstractIndexComponent.(AbstractIndexComponent.java:  
46)  
at  
org.elasticsearch.index.analysis.AbstractIndexAnalyzerProvider.(AbstractIndexAnalyzerProvider.java:  
36)  
...  
ImmutableSettings.java:  
@Override public Settings getComponentSettings(Class component) {  
return getComponentSettings("org.elasticsearch", component);  
}

```
@Override public Settings getComponentSettings(String prefix,

```

Class component) {  
String type = component.getName();  
if (!type.startsWith(prefix)) {  
throw new SettingsException("Component [" + type + "] does  
not start with prefix [" + prefix + "]");  
}  
String settingPrefix = type.substring(prefix.length() + 1); //  
1 for the '.'  
settingPrefix = settingPrefix.substring(0,  
settingPrefix.length() - component.getSimpleName().length()); //  
remove the simple class name (keep the dot)  
return getByPrefix(settingPrefix);  
}  
If I change my provider's package to begin with org.elasticsearch then  
everything works fine. However this kind of restriction is suspicious  
in nature. Why should I be required to define this class in this  
package and not in my own packages?

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [December 29, 2010, 5:16pm UTC](https://discuss.elastic.co/t/defining-a-new-analyzer-provider-forces-pakcage-name-of-the-provider-to-begin-with-org-elasticsearch/3710/2 "2010-12-29T17:16:34Z")

</div>

You're right, its annoying. The idea here is that the class is used to  
derive the component settings for that specific component by removing from  
the FQN of the class name the org.elasticsearch prefix, and removing at the  
end the simple class name. Then, its simpler to get the component settings  
for it.

I have just pushed a fix to simplify extension, if the prefix is not  
org.elasticsearch, then just the first part of the package will be used as  
the prefix (org / com / net). Also, I have added another constructor  
to AbstractIndexAnalyzerProvider that allows you to pass your own settings  
prefix (like [org.me](http://org.me)).

-shay.banon

On Wed, Dec 29, 2010 at 4:55 PM, ezb [erezmazor@gmail.com](mailto:erezmazor@gmail.com) wrote:

> My elasticsearch properties define my own type:
> 
> index.analysis.analyzer.my\_analyzer.type=org.me.index.analysis.MyWonderfulAnalyzerProvider  
> When I run it I get a  
> org.elasticsearch.common.settings.SettingsException:  
> Caused by: org.elasticsearch.common.settings.SettingsException:  
> Component [org.me.index.analysis.MyWonderfulAnalyzerProvider] does not  
> start with prefix [org.elasticsearch]  
> at
> 
> org.elasticsearch.common.settings.ImmutableSettings.getComponentSettings(ImmutableSettings.java:  
> 91)  
> at
> 
> org.elasticsearch.common.settings.ImmutableSettings.getComponentSettings(ImmutableSettings.java:  
> 85)  
> at
> 
> org.elasticsearch.index.AbstractIndexComponent.(AbstractIndexComponent.java:  
> 46)  
> at
> 
> org.elasticsearch.index.analysis.AbstractIndexAnalyzerProvider.(AbstractIndexAnalyzerProvider.java:  
> 36)  
> ...  
> ImmutableSettings.java:  
> @Override public Settings getComponentSettings(Class component) {  
> return getComponentSettings("org.elasticsearch", component);  
> }
> 
> @Override public Settings getComponentSettings(String prefix,  
> Class component) {  
> String type = component.getName();  
> if (!type.startsWith(prefix)) {  
> throw new SettingsException("Component [" + type + "] does  
> not start with prefix [" + prefix + "]");  
> }  
> String settingPrefix = type.substring(prefix.length() + 1); //  
> 1 for the '.'  
> settingPrefix = settingPrefix.substring(0,  
> settingPrefix.length() - component.getSimpleName().length()); //  
> remove the simple class name (keep the dot)  
> return getByPrefix(settingPrefix);  
> }  
> If I change my provider's package to begin with org.elasticsearch then  
> everything works fine. However this kind of restriction is suspicious  
> in nature. Why should I be required to define this class in this  
> package and not in my own packages?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 4:14am UTC](https://discuss.elastic.co/t/defining-a-new-analyzer-provider-forces-pakcage-name-of-the-provider-to-begin-with-org-elasticsearch/3710/3 "2017-07-06T04:14:41Z")

</div>


