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

One single (global) way to register custom query parsers #11481

Merged
merged 1 commit into from Jun 8, 2015

Conversation

javanna
Copy link
Member

@javanna javanna commented Jun 3, 2015

There are different ways to register custom query parsers through plugins, a couple of them work per index via index settings, which doesn't seem to be needed. There also three different ways to add a global custom query parser through either IndicesQueriesModule or IndicesQueriesRegistry. This commit consolidates the registration of custom query parsers via IndicesQueriesModule#addQuery(Class<? extends QueryParser>). The complexity of supporting parsers per index is not needed hence it got removed. Also the other ways of registering global custom parsers are dropped in favour of the one mentioned above by providing the class of the parser.

This PR breaks plugins that plug in their own custom queries. If the change looks good we can deprecate in 1.x the methods that we are removing here.

queryParsersClasses.add(queryParser);
return this;
}

public synchronized IndicesQueriesModule addQuery(QueryParser queryParser) {
Copy link
Member Author

Choose a reason for hiding this comment

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

I am conflicted on whether we should remove this or not. I think the above addQuery(Class<? extends QueryParser>) is the way to go, while this one would force binding to a specific instance. Can restore it if there is some usecase for it, it's just that I don't like having too many ways to do the same thing.

Copy link
Member

Choose a reason for hiding this comment

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

I typically defaulted to this method because it avoids the generics gymnastics I mentioned above and I'd use the Class version when I needed guice to build the query. Since you've fixed the signature above I don't see a good reason for this. If you need the global state then you can register the extra classes with guice elsewhere and have them injected.

Copy link
Member

Choose a reason for hiding this comment

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

I mean - global state in a query parser is probably a bad idea so I don't feel bad about you making it harder to do.

I have some vague worries that plugins require both an understanding of guice and Elasticsearch's onModule style initializers which makes plugin development daunting. But I don't have a solution to that. This pull request helps though, so yay!

@javanna
Copy link
Member Author

javanna commented Jun 4, 2015

@s1monw @kimchy can you have please have a look?


public synchronized IndicesQueriesModule addQuery(Class<QueryParser> queryParser) {
public synchronized IndicesQueriesModule addQuery(Class<? extends QueryParser> queryParser) {
Copy link
Member

Choose a reason for hiding this comment

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

+1 on the <? extends QueryParser> bit. I dislike the generics gymnastics you have to do to register the query without it.

@rmuir
Copy link
Contributor

rmuir commented Jun 5, 2015

This looks great to me. Much simpler!

@javanna
Copy link
Member Author

javanna commented Jun 5, 2015

thanks @rmuir for looking, I will push this soon if there are no objections (will just let the move to maven submodules settle a bit first)

@clintongormley clintongormley changed the title Plugins: one single (global) way to register custom query parsers One single (global) way to register custom query parsers Jun 6, 2015
@javanna javanna force-pushed the enhancement/custom_query_one_way branch from 4275b19 to a5c3a71 Compare June 8, 2015 08:42
@spinscale
Copy link
Contributor

LGTM

javanna added a commit to javanna/elasticsearch that referenced this pull request Jun 8, 2015
Also fix the generics in `IndicesQueriesModule#addQuery(Class)` so that it can be used as the single way to register custom query parsers.

Relates to elastic#11481
Closes elastic#11532
javanna added a commit to javanna/elasticsearch that referenced this pull request Jun 8, 2015
Also fix the generics in `IndicesQueriesModule#addQuery(Class)` so that it can be used as the single way to register custom query parsers.

Relates to elastic#11481
Closes elastic#11532
@javanna javanna changed the title One single (global) way to register custom query parsers Plugins: one single (global) way to register custom query parsers Jun 8, 2015
There are different ways to register custom query parsers through plugins, a couple of them work per index via index settings, which is probably even too flexible. There also three different ways to add a global custom query parser through either IndicesQueriesModule or IndicesQueriesRegistry. This commit consolidates the registration of custom query parsers via IndicesQueriesModule#addQuery(Class<? extends QueryParser>). The complexity of supporting parsers per index is not needed hence it got removed. Also the other ways of registering global custom parsers are dropped in favour of the one mentioned above.

Closes elastic#11481
@javanna javanna force-pushed the enhancement/custom_query_one_way branch from 1697a85 to 2ef0fcf Compare June 8, 2015 10:20
@javanna javanna merged commit 2ef0fcf into elastic:master Jun 8, 2015
@kevinkluge kevinkluge removed the review label Jun 8, 2015
@clintongormley clintongormley changed the title Plugins: one single (global) way to register custom query parsers One single (global) way to register custom query parsers Jun 10, 2015
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.

None yet

5 participants