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

Version for ES 8.14.2 #130

Merged
merged 4 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@
<jts.version>1.19.0</jts.version>
<json-path.version>2.7.0</json-path.version>

<querqy.lucene.version>5.7.lucene942.0</querqy.lucene.version>
<querqy.lucene.version>5.7.lucene961.0</querqy.lucene.version>

<elasticsearch.version>8.11.4</elasticsearch.version>
<elasticsearch.version>8.14.2</elasticsearch.version>
<jacoco.version>0.8.12</jacoco.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
Expand Down
42 changes: 18 additions & 24 deletions src/main/java/querqy/elasticsearch/QuerqyPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsFilter;
import org.elasticsearch.features.NodeFeature;
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.telemetry.TelemetryProvider;
import org.elasticsearch.xcontent.NamedXContentRegistry;
Expand Down Expand Up @@ -51,6 +52,7 @@
import java.util.Collections;
import java.util.List;
import java.util.function.Supplier;
import java.util.function.Predicate;

public class QuerqyPlugin extends Plugin implements SearchPlugin, ActionPlugin {

Expand Down Expand Up @@ -81,18 +83,21 @@ public List<QuerySpec<?>> getQueries() {
(in) -> new QuerqyQueryBuilder(in, querqyProcessor),
(parser) -> QuerqyQueryBuilder.fromXContent(parser, querqyProcessor)));
}

@Override
public List<RestHandler> getRestHandlers(final Settings settings, final RestController restController,
final ClusterSettings clusterSettings,
final IndexScopedSettings indexScopedSettings,
final SettingsFilter settingsFilter,
final IndexNameExpressionResolver indexNameExpressionResolver,
final Supplier<DiscoveryNodes> nodesInCluster) {

return Arrays.asList(new RestPutRewriterAction(), new RestDeleteRewriterAction());

}
public List<RestHandler> getRestHandlers(
final Settings settings,
final NamedWriteableRegistry namedWriteableRegistry, // This parameter was missing
final RestController restController,
final ClusterSettings clusterSettings,
final IndexScopedSettings indexScopedSettings,
final SettingsFilter settingsFilter,
final IndexNameExpressionResolver indexNameExpressionResolver,
final Supplier<DiscoveryNodes> nodesInCluster,
final Predicate<NodeFeature> clusterSupportsFeature // This parameter was missing
) {
return Arrays.asList(new RestPutRewriterAction(), new RestDeleteRewriterAction());
}

@Override
public List<ActionHandler<? extends ActionRequest, ? extends ActionResponse>> getActions() {
Expand All @@ -107,21 +112,10 @@ public List<RestHandler> getRestHandlers(final Settings settings, final RestCont
}

@Override
public Collection<Object> createComponents(final Client client, final ClusterService clusterService,
final ThreadPool threadPool,
final ResourceWatcherService resourceWatcherService,
final ScriptService scriptService,
final NamedXContentRegistry xContentRegistry,
final Environment environment, final NodeEnvironment nodeEnvironment,
final NamedWriteableRegistry namedWriteableRegistry,
final IndexNameExpressionResolver indexNameExpressionResolver,
final Supplier<RepositoriesService> repositoriesServiceSupplier,
final TelemetryProvider telemetryProvider,
final AllocationService allocationService,
final IndicesService indicesService) {
public Collection<Object> createComponents(PluginServices services) {
return Arrays.asList(rewriterShardContexts, querqyProcessor);
}

@Override
public List<Setting<?>> getSettings() {
return Collections.singletonList(Setting.intSetting(SETTINGS_QUERQY_INDEX_NUM_REPLICAS, 1, 0,
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/querqy/elasticsearch/query/Rewriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public Rewriter(final StreamInput in) throws IOException {
name = in.readString();
final boolean hasParams = in.readBoolean();
if (hasParams) {
params = in.readMap();
params = in.readGenericMap();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class DeleteRewriterAction extends ActionType<DeleteRewriterResponse> {
* @param name The name of the action, must be unique across actions.
*/
protected DeleteRewriterAction(final String name) {
super(name, DeleteRewriterResponse::new);
super(name);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class NodesClearRewriterCacheAction extends ActionType<NodesClearRewriter


protected NodesClearRewriterCacheAction(final String name) {
super(name, NodesClearRewriterCacheResponse::new);
super(name);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class NodesReloadRewriterAction extends ActionType<NodesReloadRewriterRes


protected NodesReloadRewriterAction(final String name) {
super(name, NodesReloadRewriterResponse::new);
super(name);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class PutRewriterAction extends ActionType<PutRewriterResponse> {
* @param name The name of the action, must be unique across actions.
*/
protected PutRewriterAction(final String name) {
super(name, PutRewriterResponse::new);
super(name);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class PutRewriterRequest extends ActionRequest {
public PutRewriterRequest(final StreamInput in) throws IOException {
super(in);
rewriterId = in.readString();
content = in.readMap();
content = in.readGenericMap();
}

public PutRewriterRequest(final String rewriterId, final Map<String, Object> content) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ public TransportNodesClearRewriterCacheAction(final ThreadPool threadPool, final
final Client client,
final RewriterShardContexts rewriterShardContexts) {

super(NodesClearRewriterCacheAction.NAME, threadPool, clusterService, transportService, actionFilters,
NodesClearRewriterCacheRequest::new, NodesClearRewriterCacheRequest.NodeRequest::new,
threadPool.executor(ThreadPool.Names.MANAGEMENT));
this.rewriterShardContexts = rewriterShardContexts;
super(
NodesClearRewriterCacheAction.NAME,
clusterService,
transportService,
actionFilters,
NodesClearRewriterCacheRequest.NodeRequest::new,
threadPool.executor(ThreadPool.Names.MANAGEMENT));
this.rewriterShardContexts = rewriterShardContexts;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,16 @@ public TransportNodesReloadRewriterAction(final ThreadPool threadPool, final Clu
final Client client,
final RewriterShardContexts rewriterShardContexts) {

super(NodesReloadRewriterAction.NAME, threadPool, clusterService, transportService, actionFilters,
NodesReloadRewriterRequest::new, NodesReloadRewriterRequest.NodeRequest::new,
threadPool.executor(ThreadPool.Names.MANAGEMENT));
this.rewriterShardContexts = rewriterShardContexts;
this.client = client;
this.indexServices = indexServices;
super(
NodesReloadRewriterAction.NAME,
clusterService,
transportService,
actionFilters,
NodesReloadRewriterRequest.NodeRequest::new,
threadPool.executor(ThreadPool.Names.MANAGEMENT));
this.rewriterShardContexts = rewriterShardContexts;
this.client = client;
this.indexServices = indexServices;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse;
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
import org.elasticsearch.action.index.IndexAction;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.HandledTransportAction;
import org.elasticsearch.action.support.WriteRequest;
Expand Down Expand Up @@ -195,11 +195,9 @@ protected CreateIndexRequest buildCreateQuerqyIndexRequest(final IndicesAdminCli

protected void saveRewriter(final Task task, final PutRewriterRequest request,
final ActionListener<PutRewriterResponse> listener) throws IOException {
final ActionRequest indexRequest = buildIndexRequest(task, request);
final IndexRequest indexRequest = buildIndexRequest(task, request);

client.execute(IndexAction.INSTANCE, indexRequest,

new ActionListener<>() {
client.index(indexRequest, new ActionListener<>() {
@Override
public void onResponse(final DocWriteResponse indexResponse) {
LOGGER.info("Saved rewriter {}", request.getRewriterId());
Expand All @@ -221,15 +219,15 @@ public void onFailure(final Exception e) {
;
}

private ActionRequest buildIndexRequest(final Task parentTask, final PutRewriterRequest request) throws IOException {
private IndexRequest buildIndexRequest(final Task parentTask, final PutRewriterRequest request) throws IOException {
IndexRequest indexRequest = new IndexRequest(QUERQY_INDEX_NAME)
.id(request.getRewriterId())
.create(false)
.source(RewriterConfigMapping.toLuceneSource(request.getContent()), XContentType.JSON);

final ActionRequest indexRequest = client.prepareIndex(QUERQY_INDEX_NAME)
.setId(request.getRewriterId())
.setCreate(false)
.setSource(RewriterConfigMapping.toLuceneSource(request.getContent()))
.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
.request();
indexRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
indexRequest.setParentTask(clusterService.localNode().getId(), parentTask.getId());

return indexRequest;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public void testThatQueryAnalyzerIsApplied() throws Exception {

SearchResponse response = client().search(searchRequestBuilder.request()).get();
assertEquals(1L, response.getHits().getTotalHits().value);
response.decRef();

final QuerqyQueryBuilder queryAnalyzerMismatch = new QuerqyQueryBuilder(
getInstanceFromNode(QuerqyProcessor.class));
Expand All @@ -49,6 +50,7 @@ public void testThatQueryAnalyzerIsApplied() throws Exception {

response = client().search(searchRequestBuilder.request()).get();
assertEquals(0L, response.getHits().getTotalHits().value);
response.decRef();

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,6 @@ public void testUpdate1To3() throws Exception {
assertEquals(false, config_v_003_mapping.get("doc_values"));

}


}
23 changes: 14 additions & 9 deletions src/test/java/querqy/elasticsearch/RewriterIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void testSearchWithConfig() throws Exception {

final PutRewriterRequest request = new PutRewriterRequest("common_rules", content);

client().execute(PutRewriterAction.INSTANCE, request).get();
client().execute(PutRewriterAction.INSTANCE, request).get().decRef();

QuerqyQueryBuilder querqyQuery = new QuerqyQueryBuilder(getInstanceFromNode(QuerqyProcessor.class));
querqyQuery.setRewriters(Collections.singletonList(new Rewriter("common_rules")));
Expand All @@ -65,6 +65,7 @@ public void testSearchWithConfig() throws Exception {

SearchResponse response = client().search(searchRequestBuilder.request()).get();
assertEquals(2L, response.getHits().getTotalHits().value);
response.decRef();

}

Expand All @@ -82,7 +83,7 @@ public void testRawQuery() throws Exception {

final PutRewriterRequest request = new PutRewriterRequest("common_rules", content);

client().execute(PutRewriterAction.INSTANCE, request).get();
client().execute(PutRewriterAction.INSTANCE, request).get().decRef();

QuerqyQueryBuilder querqyQuery = new QuerqyQueryBuilder(getInstanceFromNode(QuerqyProcessor.class));
querqyQuery.setRewriters(Collections.singletonList(new Rewriter("common_rules")));
Expand All @@ -97,6 +98,7 @@ public void testRawQuery() throws Exception {
final SearchHits hits = response.getHits();
assertEquals(1L, hits.getTotalHits().value);
assertEquals("a c", hits.getHits()[0].getSourceAsMap().get("field2"));
response.decRef();
}

@Test
Expand Down Expand Up @@ -124,6 +126,7 @@ public void testLargeConfig() throws Exception {
final PutRewriterResponse response = client().execute(PutRewriterAction.INSTANCE, request).get();

assertEquals(RestStatus.CREATED, response.status());
response.decRef();

}

Expand All @@ -142,7 +145,7 @@ public void testSearchWithUpdatedConfig() throws Exception {

final PutRewriterRequest request = new PutRewriterRequest("common_rules", content);

client().execute(PutRewriterAction.INSTANCE, request).get();
client().execute(PutRewriterAction.INSTANCE, request).get().decRef();

QuerqyQueryBuilder querqyQuery = new QuerqyQueryBuilder(getInstanceFromNode(QuerqyProcessor.class));
querqyQuery.setRewriters(Collections.singletonList(new Rewriter("common_rules")));
Expand All @@ -155,6 +158,7 @@ public void testSearchWithUpdatedConfig() throws Exception {

SearchResponse response = client().search(searchRequestBuilder.request()).get();
assertEquals(1L, response.getHits().getTotalHits().value);
response.decRef();


final Map<String, Object> content2 = new HashMap<>();
Expand All @@ -167,7 +171,7 @@ public void testSearchWithUpdatedConfig() throws Exception {
content2.put("config", config2);

final PutRewriterRequest request2 = new PutRewriterRequest("common_rules", content2);
client().execute(PutRewriterAction.INSTANCE, request2).get();
client().execute(PutRewriterAction.INSTANCE, request2).get().decRef();

QuerqyQueryBuilder querqyQuery2 = new QuerqyQueryBuilder(getInstanceFromNode(QuerqyProcessor.class));
querqyQuery2.setRewriters(Collections.singletonList(new Rewriter("common_rules")));
Expand All @@ -180,6 +184,7 @@ public void testSearchWithUpdatedConfig() throws Exception {

SearchResponse response2 = client().search(searchRequestBuilder2.request()).get();
assertEquals(2L, response2.getHits().getTotalHits().value);
response2.decRef();

}

Expand All @@ -199,7 +204,7 @@ public void testThatRewriterIsDeleted() throws Exception {

final PutRewriterRequest request = new PutRewriterRequest("common_rules", content);

client().execute(PutRewriterAction.INSTANCE, request).get();
client().execute(PutRewriterAction.INSTANCE, request).get().decRef();

QuerqyQueryBuilder querqyQuery = new QuerqyQueryBuilder(getInstanceFromNode(QuerqyProcessor.class));
querqyQuery.setRewriters(Collections.singletonList(new Rewriter("common_rules")));
Expand All @@ -212,10 +217,10 @@ public void testThatRewriterIsDeleted() throws Exception {

SearchResponse response = client().search(searchRequestBuilder.request()).get();
assertEquals(2L, response.getHits().getTotalHits().value);

response.decRef();

final DeleteRewriterRequest delRequest = new DeleteRewriterRequest("common_rules");
client().execute(DeleteRewriterAction.INSTANCE, delRequest).get();
client().execute(DeleteRewriterAction.INSTANCE, delRequest).get().decRef();

QuerqyQueryBuilder querqyQuery2 = new QuerqyQueryBuilder(getInstanceFromNode(QuerqyProcessor.class));
querqyQuery2.setRewriters(Collections.singletonList(new Rewriter("common_rules")));
Expand All @@ -227,7 +232,7 @@ public void testThatRewriterIsDeleted() throws Exception {
searchRequestBuilder2.setQuery(querqyQuery2);

try {
client().search(searchRequestBuilder.request()).get();
client().search(searchRequestBuilder.request()).get().decRef();
fail("Could use deleted rewriter in request");
} catch (final ExecutionException e) {
assertTrue(e.getMessage().contains("Rewriter not found: common_rules"));
Expand All @@ -239,7 +244,7 @@ public void testThatRewriterIsDeleted() throws Exception {

@After
public void deleteRewriterIndex() {
client().admin().indices().prepareDelete(".querqy").get();
client().admin().indices().prepareDelete(".querqy").get().decRef();
}


Expand Down
Loading
Loading