Skip to content

Commit

Permalink
Es 7 12 (#364)
Browse files Browse the repository at this point in the history
* wip for 7.11 deprecations

* Fix build errors for 7.11

* add public visibility to test templates

* keeping threadpool over executor for now

* remove all the checks except keep nebula disabled

* Restore override annotation in TransportAddFeatureToSet

* read() was removed

* Bring back checkstyle and fix some violations

* Clean up unused vars

* 7.12 changes

Co-authored-by: Nathan Day <[email protected]>
  • Loading branch information
worleydl and nathancday authored Apr 27, 2021
1 parent 58a8513 commit 48cd016
Show file tree
Hide file tree
Showing 15 changed files with 62 additions and 59 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ltrVersion = 1.5.4
elasticsearchVersion = 7.11.1
luceneVersion = 8.7.0
elasticsearchVersion = 7.12.0
luceneVersion = 8.8.0
ow2Version = 8.0.1
antlrVersion = 4.5.1-1
4 changes: 2 additions & 2 deletions src/main/java/com/o19s/es/explore/ExplorerQueryBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.elasticsearch.index.query.AbstractQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryRewriteContext;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.index.query.SearchExecutionContext;
import org.elasticsearch.index.query.Rewriteable;

import java.io.IOException;
Expand Down Expand Up @@ -98,7 +98,7 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep
}

@Override
protected Query doToQuery(QueryShardContext context) throws IOException {
protected Query doToQuery(SearchExecutionContext context) throws IOException {
return new ExplorerQuery(query.toQuery(context), type);
}

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/o19s/es/ltr/LtrQueryContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.o19s.es.ltr;

import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.index.query.SearchExecutionContext;

import java.util.Collections;
import java.util.Set;
Expand All @@ -25,19 +25,19 @@
* LTR queryShardContext used to track information needed for building lucene queries
*/
public class LtrQueryContext {
private final QueryShardContext queryShardContext;
private final SearchExecutionContext queryShardContext;
private final Set<String> activeFeatures;

public LtrQueryContext(QueryShardContext context) {
public LtrQueryContext(SearchExecutionContext context) {
this(context, Collections.emptySet());
}

public LtrQueryContext(QueryShardContext context, Set<String> activeFeatures) {
public LtrQueryContext(SearchExecutionContext context, Set<String> activeFeatures) {
this.queryShardContext = context;
this.activeFeatures = activeFeatures;
}

public QueryShardContext getQueryShardContext() {
public SearchExecutionContext getSearchExecutionContext() {
return queryShardContext;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,15 @@ public Query doToQuery(LtrQueryContext context, FeatureSet set, Map<String, Obje
String query = MustacheUtils.execute(template, params);
try {
XContentParser parser = XContentFactory.xContent(query)
.createParser(context.getQueryShardContext().getXContentRegistry(),
.createParser(context.getSearchExecutionContext().getXContentRegistry(),
LoggingDeprecationHandler.INSTANCE, query);
QueryBuilder queryBuilder = parseInnerQueryBuilder(parser);
// XXX: QueryShardContext extends QueryRewriteContext (for now)
return Rewriteable.rewrite(queryBuilder, context.getQueryShardContext()).toQuery(context.getQueryShardContext());
return Rewriteable.rewrite(queryBuilder, context.getSearchExecutionContext()).toQuery(context.getSearchExecutionContext());
} catch (IOException | ParsingException | IllegalArgumentException e) {
// wrap common exceptions as well so we can attach the feature's name to the stack
throw new QueryShardException(context.getQueryShardContext(), "Cannot create query while parsing feature [" + name + "]", e);
throw new QueryShardException(context.getSearchExecutionContext(),
"Cannot create query while parsing feature [" + name + "]", e);
}
}

Expand Down
14 changes: 7 additions & 7 deletions src/main/java/com/o19s/es/ltr/feature/store/ScriptFeature.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,10 @@ public Query doToQuery(LtrQueryContext context, FeatureSet featureSet, Map<Strin
Analyzer analyzer = null;
for(String field : fields) {
if (analyzerName == null) {
final MappedFieldType fieldType = context.getQueryShardContext().getFieldType(field);
final MappedFieldType fieldType = context.getSearchExecutionContext().getFieldType(field);
analyzer = fieldType.getTextSearchInfo().getSearchAnalyzer();
} else {
analyzer = context.getQueryShardContext().getIndexAnalyzers().get(analyzerName);
analyzer = context.getSearchExecutionContext().getIndexAnalyzers().get(analyzerName);
}

if (analyzer == null) {
Expand Down Expand Up @@ -211,12 +211,12 @@ public Query doToQuery(LtrQueryContext context, FeatureSet featureSet, Map<Strin
nparams.put(EXTRA_LOGGING, extraLoggingSupplier);
Script script = new Script(this.script.getType(), this.script.getLang(),
this.script.getIdOrCode(), this.script.getOptions(), nparams);
ScoreScript.Factory factoryFactory = context.getQueryShardContext().compile(script, ScoreScript.CONTEXT);
ScoreScript.LeafFactory leafFactory = factoryFactory.newFactory(nparams, context.getQueryShardContext().lookup());
ScoreScript.Factory factoryFactory = context.getSearchExecutionContext().compile(script, ScoreScript.CONTEXT);
ScoreScript.LeafFactory leafFactory = factoryFactory.newFactory(nparams, context.getSearchExecutionContext().lookup());
ScriptScoreFunction function = new ScriptScoreFunction(script, leafFactory,
context.getQueryShardContext().index().getName(),
context.getQueryShardContext().getShardId(),
context.getQueryShardContext().indexVersionCreated());
context.getSearchExecutionContext().index().getName(),
context.getSearchExecutionContext().getShardId(),
context.getSearchExecutionContext().indexVersionCreated());
return new LtrScript(function, supplier, extraLoggingSupplier, termstatSupplier, terms);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,11 @@ public Query doToQuery(LtrQueryContext context, FeatureSet set, Map<String, Obje
// TODO: verify that this actually works, it does not feel right
ScriptQueryBuilder builder = new ScriptQueryBuilder(new Script(ScriptType.INLINE, templateLanguage, template, params));
try {
return builder.toQuery(context.getQueryShardContext());
return builder.toQuery(context.getSearchExecutionContext());
} catch (IOException | ParsingException | IllegalArgumentException e) {
// wrap common exceptions as well so we can attach the feature's name to the stack
throw new QueryShardException(context.getQueryShardContext(), "Cannot create query while parsing feature [" + name + "]", e);
throw new QueryShardException(context.getSearchExecutionContext(),
"Cannot create query while parsing feature [" + name + "]", e);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/o19s/es/ltr/query/LtrQueryBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import org.elasticsearch.index.query.MatchAllQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryRewriteContext;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.index.query.SearchExecutionContext;
import org.elasticsearch.index.query.Rewriteable;
import org.elasticsearch.script.Script;

Expand Down Expand Up @@ -122,7 +122,7 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep
}

@Override
protected Query doToQuery(QueryShardContext context) throws IOException {
protected Query doToQuery(SearchExecutionContext context) throws IOException {
List<PrebuiltFeature> features = new ArrayList<>(_features.size());
for (QueryBuilder builder : _features) {
features.add(new PrebuiltFeature(builder.queryName(), builder.toQuery(context)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.query.AbstractQueryBuilder;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.index.query.SearchExecutionContext;

import java.io.IOException;
import java.util.Arrays;
Expand Down Expand Up @@ -66,7 +66,7 @@ public class StoredLtrQueryBuilder extends AbstractQueryBuilder<StoredLtrQueryBu
}

/**
* Injected context used to load a {@link FeatureStore} when running {@link #doToQuery(QueryShardContext)}
* Injected context used to load a {@link FeatureStore} when running {@link #doToQuery(SearchExecutionContext)}
*/
private final transient FeatureStoreLoader storeLoader;
private String modelName;
Expand Down Expand Up @@ -153,7 +153,7 @@ private static void validateActiveFeatures(FeatureSet features, LtrQueryContext
}

@Override
protected RankerQuery doToQuery(QueryShardContext context) throws IOException {
protected RankerQuery doToQuery(SearchExecutionContext context) throws IOException {
String indexName = storeName != null ? IndexFeatureStore.indexName(storeName) : IndexFeatureStore.DEFAULT_STORE;
FeatureStore store = storeLoader.load(indexName, context::getClient);
LtrQueryContext ltrQueryContext = new LtrQueryContext(context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.query.AbstractQueryBuilder;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.index.query.SearchExecutionContext;
import org.elasticsearch.index.query.QueryShardException;

import java.io.IOException;
Expand Down Expand Up @@ -158,9 +158,9 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep
}

@Override
protected Query doToQuery(QueryShardContext queryShardContext) throws IOException {
protected Query doToQuery(SearchExecutionContext searchExecutionContext) throws IOException {
//TODO: should we be passing activeFeatures here?
LtrQueryContext context = new LtrQueryContext(queryShardContext);
LtrQueryContext context = new LtrQueryContext(searchExecutionContext);
if (StoredFeature.TYPE.equals(element.type())) {
Feature feature = ((StoredFeature) element).optimize();
if (feature instanceof PrecompiledExpressionFeature) {
Expand All @@ -178,7 +178,7 @@ protected Query doToQuery(QueryShardContext queryShardContext) throws IOExceptio
CompiledLtrModel model = ((StoredLtrModel) element).compile(factory);
return RankerQuery.build(model, context, validation.getParams());
} else {
throw new QueryShardException(queryShardContext, "Unknown element type [" + element.type() + "]");
throw new QueryShardException(searchExecutionContext, "Unknown element type [" + element.type() + "]");
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/o19s/es/termstat/TermStatQueryBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.query.AbstractQueryBuilder;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.index.query.SearchExecutionContext;

import java.io.IOException;
import java.util.Arrays;
Expand Down Expand Up @@ -134,7 +134,7 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep
}

@Override
protected Query doToQuery(QueryShardContext context) throws IOException {
protected Query doToQuery(SearchExecutionContext context) throws IOException {
Expression compiledExpression = (Expression) Scripting.compile(expr);
AggrType aggrType = AggrType.valueOf(aggr.toUpperCase(Locale.getDefault()));
AggrType posAggrType = AggrType.valueOf(pos_aggr.toUpperCase(Locale.getDefault()));
Expand Down Expand Up @@ -169,12 +169,12 @@ protected Query doToQuery(QueryShardContext context) throws IOException {
return new TermStatQuery(compiledExpression, aggrType, posAggrType, termSet);
}

private Analyzer getAnalyzerForField(QueryShardContext context, String fieldName) {
private Analyzer getAnalyzerForField(SearchExecutionContext context, String fieldName) {
MappedFieldType fieldType = context.getFieldType(fieldName);
return fieldType.getTextSearchInfo().getSearchAnalyzer();
}

private Analyzer getAnalyzerByName(QueryShardContext context, String analyzerName) {
private Analyzer getAnalyzerByName(SearchExecutionContext context, String analyzerName) {
return context.getIndexAnalyzers().get(analyzerName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.elasticsearch.common.ParsingException;
import org.elasticsearch.index.query.AbstractQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.index.query.SearchExecutionContext;
import org.elasticsearch.index.query.TermQueryBuilder;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.AbstractQueryTestCase;
Expand Down Expand Up @@ -66,7 +66,7 @@ public void testParse() throws Exception {

@Override
public void testMustRewrite() throws IOException {
QueryShardContext context = createShardContext();
SearchExecutionContext context = createSearchExecutionContext();
context.setAllowUnmappedFields(true);
ExplorerQueryBuilder queryBuilder = createTestQueryBuilder();
queryBuilder.boost(AbstractQueryBuilder.DEFAULT_BOOST);
Expand Down Expand Up @@ -104,7 +104,7 @@ public void testMissingType() throws Exception {
}

@Override
protected void doAssertLuceneQuery(ExplorerQueryBuilder queryBuilder, Query query, QueryShardContext context) throws IOException {
protected void doAssertLuceneQuery(ExplorerQueryBuilder queryBuilder, Query query, SearchExecutionContext context) throws IOException {
assertThat(query, instanceOf(ExplorerQuery.class));
}
}
14 changes: 7 additions & 7 deletions src/test/java/com/o19s/es/ltr/query/LtrQueryBuilderTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.elasticsearch.index.query.MatchAllQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.MatchQueryBuilder;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.index.query.SearchExecutionContext;
import org.elasticsearch.index.query.WrapperQueryBuilder;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.script.Script;
Expand Down Expand Up @@ -125,7 +125,7 @@ public void testNamedFeatures() throws IOException {
" } " +
"}";
LtrQueryBuilder queryBuilder = (LtrQueryBuilder)parseQuery(ltrQuery);
QueryShardContext context = createShardContext();
SearchExecutionContext context = createSearchExecutionContext();
RankerQuery query = (RankerQuery)queryBuilder.toQuery(context);
assertEquals(query.getFeature(0).name(), "bar_query");
assertEquals(query.getFeature(1).name(), "sham_query");
Expand All @@ -152,7 +152,7 @@ public void testUnnamedFeatures() throws IOException {
" } " +
"}";
LtrQueryBuilder queryBuilder = (LtrQueryBuilder)parseQuery(ltrQuery);
QueryShardContext context = createShardContext();
SearchExecutionContext context = createSearchExecutionContext();
RankerQuery query = (RankerQuery)queryBuilder.toQuery(context);
assertNull(query.getFeature(0).name());
assertEquals(query.getFeature(1).name(), "");
Expand All @@ -167,9 +167,9 @@ protected boolean builderGeneratesCacheableQueries() {
@Override
public void testCacheability() throws IOException {
LtrQueryBuilder queryBuilder = createTestQueryBuilder();
QueryShardContext context = createShardContext();
SearchExecutionContext context = createSearchExecutionContext();
assert context.isCacheable();
QueryBuilder rewritten = rewriteQuery(queryBuilder, new QueryShardContext(context));
QueryBuilder rewritten = rewriteQuery(queryBuilder, new SearchExecutionContext(context));
assertNotNull(rewritten.toQuery(context));
assertTrue("query should be cacheable: " + queryBuilder.toString(), context.isCacheable());
}
Expand Down Expand Up @@ -215,7 +215,7 @@ public void testMustRewrite() throws IOException {
}

LtrQueryBuilder builder = new LtrQueryBuilder(script, features);
QueryBuilder rewritten = builder.rewrite(createShardContext());
QueryBuilder rewritten = builder.rewrite(createSearchExecutionContext());
if (!mustRewrite && features.isEmpty()) {
// if it's empty we rewrite to match all
assertEquals(rewritten, new MatchAllQueryBuilder());
Expand All @@ -235,7 +235,7 @@ public void testMustRewrite() throws IOException {
}

@Override
protected void doAssertLuceneQuery(LtrQueryBuilder queryBuilder, Query query, QueryShardContext context) throws IOException {
protected void doAssertLuceneQuery(LtrQueryBuilder queryBuilder, Query query, SearchExecutionContext context) throws IOException {
assertThat(query, instanceOf(RankerQuery.class));
}

Expand Down
Loading

0 comments on commit 48cd016

Please sign in to comment.