Skip to content

Commit a666fb2

Browse files
gaobinlongChristoph Büscher
authored and
Christoph Büscher
committed
Fix _analyze API to correctly use normalizers when specified (#48866)
Currently the `_analyze` endpoint doesn't correctly use normalizers specified in the request. This change fixes that by returning the resolved normalizer from TransportAnalyzeAction#getAnalyzer and updates test to be able to catch this in the future. Closes #48650
1 parent e0df257 commit a666fb2

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

server/src/main/java/org/elasticsearch/action/admin/indices/analyze/TransportAnalyzeAction.java

+1
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ private static Analyzer getAnalyzer(AnalyzeAction.Request request, AnalysisRegis
171171
if (analyzer == null) {
172172
throw new IllegalArgumentException("failed to find normalizer under [" + request.normalizer() + "]");
173173
}
174+
return analyzer;
174175
}
175176
if (request.field() != null) {
176177
if (indexService == null) {

server/src/test/java/org/elasticsearch/action/admin/indices/TransportAnalyzeActionTests.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -428,13 +428,14 @@ public void testCustomCharFilterWithParameters() throws IOException {
428428
public void testNormalizerWithIndex() throws IOException {
429429
AnalyzeAction.Request request = new AnalyzeAction.Request("index");
430430
request.normalizer("my_normalizer");
431-
request.text("ABc");
431+
// this should be lowercased and only emit a single token
432+
request.text("Wi-fi");
432433
AnalyzeAction.Response analyze
433434
= TransportAnalyzeAction.analyze(request, registry, mockIndexService(), maxTokenCount);
434435
List<AnalyzeAction.AnalyzeToken> tokens = analyze.getTokens();
435436

436437
assertEquals(1, tokens.size());
437-
assertEquals("abc", tokens.get(0).getTerm());
438+
assertEquals("wi-fi", tokens.get(0).getTerm());
438439
}
439440

440441
/**

0 commit comments

Comments
 (0)