DummyQueryParserPlugin doesn't compile out of package

I've been working on a custom query / custom query builder. As a starting point, I copy/pasted DummyQueryBuilder and DummyQueryParserPlugin out of Elasticsearch's source and into my package. I've only changed the package.

Unfortunately, this code by itself, only changing the package doesn't compile. I get an error in DummyQueryParserPlugin on this line:

@Override
public List<QuerySpec<?>> getQueries() {
    return singletonList(new QuerySpec<>(DummyQueryBuilder.NAME, DummyQueryBuilder::new, DummyQueryBuilder::fromXContent));
}

Error:(40, 34) java: cannot infer type arguments for org.elasticsearch.plugins.SearchPlugin.QuerySpec<>

I've seen this on Java 7 and 8. I'm using Elasticsearch 5.1.1

Should I expect this line to work outside of package org.elasticsearch.index.query.plugin;?

I solved it, though I'm not entirely sure why it matters. The issue boils down to the fact that the QueryParser interface is a functional interface that experts fromXContent to return an Optional<DummyQueryBuilder>. By performing that conversion directly, I can get it to work. So this code works:

    @Override
    public List<QuerySpec<?>> getQueries() {
        QueryParser<DummyQueryBuilder> qp = new QueryParser<DummyQueryBuilder>() {
            @Override
            public Optional<DummyQueryBuilder> fromXContent(QueryParseContext parseContext) throws IOException {
                Optional<DummyQueryBuilder> opt;
                opt = Optional.of(DummyQueryBuilder.fromXContent(parseContext));
                return opt;

            }
        };
        return singletonList(new QuerySpec<>(DummyQueryBuilder.NAME, DummyQueryBuilder::new, qp));
    }
2 Likes

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.