From c929d466418e232dbd277893138f91a7824f0a6e Mon Sep 17 00:00:00 2001 From: bellengao Date: Tue, 5 Nov 2019 22:04:28 +0800 Subject: [PATCH 1/2] Fix _analyze api does not correctly use normalizers when specified (#48650) --- .../action/admin/indices/analyze/TransportAnalyzeAction.java | 1 + .../action/admin/indices/TransportAnalyzeActionTests.java | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/analyze/TransportAnalyzeAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/analyze/TransportAnalyzeAction.java index 2e88c32a3421b..2b94e872c5e1d 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/analyze/TransportAnalyzeAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/analyze/TransportAnalyzeAction.java @@ -171,6 +171,7 @@ private static Analyzer getAnalyzer(AnalyzeAction.Request request, AnalysisRegis if (analyzer == null) { throw new IllegalArgumentException("failed to find normalizer under [" + request.normalizer() + "]"); } + return analyzer; } if (request.field() != null) { if (indexService == null) { diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/TransportAnalyzeActionTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/TransportAnalyzeActionTests.java index 6abff5f0a817e..0e64d842aa932 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/TransportAnalyzeActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/TransportAnalyzeActionTests.java @@ -428,13 +428,13 @@ public void testCustomCharFilterWithParameters() throws IOException { public void testNormalizerWithIndex() throws IOException { AnalyzeAction.Request request = new AnalyzeAction.Request("index"); request.normalizer("my_normalizer"); - request.text("ABc"); + request.text("Wi-fi"); AnalyzeAction.Response analyze = TransportAnalyzeAction.analyze(request, registry, mockIndexService(), maxTokenCount); List tokens = analyze.getTokens(); assertEquals(1, tokens.size()); - assertEquals("abc", tokens.get(0).getTerm()); + assertEquals("wi-fi", tokens.get(0).getTerm()); } /** From 9b54e294ca53fee8b8f2ee2aa5f69a78a1cd3249 Mon Sep 17 00:00:00 2001 From: bellengao Date: Thu, 14 Nov 2019 10:37:13 +0800 Subject: [PATCH 2/2] Add comment for testing normalizer Add a comment to explain the result when using custom normalizer --- .../action/admin/indices/TransportAnalyzeActionTests.java | 1 + 1 file changed, 1 insertion(+) diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/TransportAnalyzeActionTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/TransportAnalyzeActionTests.java index 0e64d842aa932..23129ae546fe6 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/TransportAnalyzeActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/TransportAnalyzeActionTests.java @@ -428,6 +428,7 @@ public void testCustomCharFilterWithParameters() throws IOException { public void testNormalizerWithIndex() throws IOException { AnalyzeAction.Request request = new AnalyzeAction.Request("index"); request.normalizer("my_normalizer"); + // this should be lowercased and only emit a single token request.text("Wi-fi"); AnalyzeAction.Response analyze = TransportAnalyzeAction.analyze(request, registry, mockIndexService(), maxTokenCount);