Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 6 additions & 0 deletions docs/changelog/121568.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 121568
summary: Analyze API to return 400 for wrong custom analyzer
area: Analysis
type: bug
issues:
- 121443
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,24 @@
- match: { detail.tokenizer.tokens.0.token: ABc }
- match: { detail.tokenfilters.0.name: lowercase }
- match: { detail.tokenfilters.0.tokens.0.token: abc }

---
"Custom analyzer is not buildable":
- requires:
cluster_features: [ "wrong_custom_analyzer_return_400" ]
reason: "Returning 400 for wrong custom analyzer was added in this version"

- do:
catch: bad_request
indices.analyze:
body:
text: the foxes jumping quickly
tokenizer:
standard
filter:
type: hunspell
locale: en_US

- match: { status: 400 }
- match: { error.type: illegal_argument_exception }
- match: { error.reason: "Can not build a custom analyzer" }
2 changes: 2 additions & 0 deletions server/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@
provides org.elasticsearch.features.FeatureSpecification
with
org.elasticsearch.action.bulk.BulkFeatures,
org.elasticsearch.action.admin.ActionFeatures,
org.elasticsearch.features.FeatureInfrastructureFeatures,
org.elasticsearch.rest.action.admin.cluster.ClusterRerouteFeatures,
org.elasticsearch.index.mapper.MapperFeatures,
Expand Down Expand Up @@ -476,4 +477,5 @@
exports org.elasticsearch.monitor.metrics;
exports org.elasticsearch.plugins.internal.rewriter to org.elasticsearch.inference;
exports org.elasticsearch.lucene.util.automaton;
exports org.elasticsearch.action.admin;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

package org.elasticsearch.action.admin;

import org.elasticsearch.features.FeatureSpecification;
import org.elasticsearch.features.NodeFeature;

import java.util.Set;

import static org.elasticsearch.action.admin.indices.analyze.TransportAnalyzeAction.WRONG_CUSTOM_ANALYZER_RETURN_400;

public class ActionFeatures implements FeatureSpecification {

@Override
public Set<NodeFeature> getFeatures() {
return Set.of();
}

@Override
public Set<NodeFeature> getTestFeatures() {
return Set.of(WRONG_CUSTOM_ANALYZER_RETURN_400);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.core.IOUtils;
import org.elasticsearch.features.NodeFeature;
import org.elasticsearch.index.IndexService;
import org.elasticsearch.index.IndexService.IndexCreationContext;
import org.elasticsearch.index.IndexSettings;
Expand Down Expand Up @@ -65,6 +66,8 @@
*/
public class TransportAnalyzeAction extends TransportSingleShardAction<AnalyzeAction.Request, AnalyzeAction.Response> {

public static final NodeFeature WRONG_CUSTOM_ANALYZER_RETURN_400 = new NodeFeature("wrong_custom_analyzer_return_400");
Copy link
Contributor

Choose a reason for hiding this comment

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

more for curiosity does this need to be a nodefeature or can it be a test feature. it's unfortunate stuff like this has to be enumerated.

Copy link
Member

Choose a reason for hiding this comment

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

Could you simply make this a capability on the REST API side? That is much simpler and then you don't need all these feature things.


private final Settings settings;
private final IndicesService indicesService;

Expand Down Expand Up @@ -144,6 +147,8 @@ public static AnalyzeAction.Response analyze(
if (analyzer != null) {
return analyze(request, analyzer, maxTokenCount);
}
} catch (IllegalStateException e) {
throw new IllegalArgumentException("Can not build a custom analyzer", e);
}

// Otherwise we use a built-in analyzer, which should not be closed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#

org.elasticsearch.action.bulk.BulkFeatures
org.elasticsearch.action.admin.ActionFeatures
org.elasticsearch.features.FeatureInfrastructureFeatures
org.elasticsearch.rest.action.admin.cluster.ClusterRerouteFeatures
org.elasticsearch.index.IndexFeatures
Expand Down