Skip to content

Commit 7ead9e2

Browse files
committed
es 8.7.0 support
1 parent 979f8ce commit 7ead9e2

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>org.ansj</groupId>
66
<artifactId>elasticsearch-analysis-ansj</artifactId>
7-
<version>8.6.2.0</version>
7+
<version>8.7.0.0</version>
88
<description>elasticsearch analysis by ansj</description>
99
<name>elasticsearch-analysis-ansj</name>
1010
<url>http://maven.nlpcn.org</url>
@@ -14,7 +14,7 @@
1414
<runSuite>**/MainTestSuite.class</runSuite>
1515
<elasticsearch.plugin.name>elasticsearch-analysis-ansj</elasticsearch.plugin.name>
1616
<elasticsearch.plugin.java.version>17</elasticsearch.plugin.java.version>
17-
<elasticsearch.version>8.6.2</elasticsearch.version>
17+
<elasticsearch.version>8.7.0</elasticsearch.version>
1818
<elasticsearch.plugin.classname>org.ansj.elasticsearch.plugin.AnalysisAnsjPlugin</elasticsearch.plugin.classname>
1919
</properties>
2020

src/main/java/org/ansj/elasticsearch/cat/ChineseRestTable.java

+10-7
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
import org.elasticsearch.common.Strings;
2323
import org.elasticsearch.common.Table;
24-
import org.elasticsearch.common.io.UTF8StreamWriter;
24+
import org.elasticsearch.common.io.Streams;
2525
import org.elasticsearch.common.io.stream.BytesStream;
2626
import org.elasticsearch.common.regex.Regex;
2727
import org.elasticsearch.common.unit.ByteSizeValue;
@@ -36,6 +36,8 @@
3636
import org.elasticsearch.xcontent.XContentType;
3737

3838
import java.io.IOException;
39+
import java.io.OutputStreamWriter;
40+
import java.nio.charset.StandardCharsets;
3941
import java.util.ArrayList;
4042
import java.util.LinkedHashSet;
4143
import java.util.List;
@@ -57,11 +59,11 @@ public static RestResponse buildResponse(Table table, RestChannel channel) throw
5759
}
5860

5961
public static RestResponse response(RestChannel channel, String text) throws IOException {
60-
try (UTF8StreamWriter out = new UTF8StreamWriter(); BytesStream bytesOut = channel.bytesOutput()) {
61-
out.setOutput(bytesOut);
62+
BytesStream bytesOut = Streams.flushOnCloseStream(channel.bytesOutput());
63+
try (OutputStreamWriter out = new OutputStreamWriter(bytesOut, StandardCharsets.UTF_8)) {
6264
out.append(text);
63-
return new RestResponse(RestStatus.OK, RestResponse.TEXT_CONTENT_TYPE, bytesOut.bytes());
6465
}
66+
return new RestResponse(RestStatus.OK, RestResponse.TEXT_CONTENT_TYPE, bytesOut.bytes());
6567
}
6668

6769
public static RestResponse response(RestChannel channel, Map<String, Object> map) throws IOException {
@@ -96,7 +98,8 @@ public static RestResponse buildTextPlainResponse(Table table, RestChannel chann
9698
List<DisplayHeader> headers = buildDisplayHeaders(table, request);
9799
int[] width = buildWidths(table, request, verbose, headers);
98100

99-
try (BytesStream bytesOut = channel.bytesOutput(); UTF8StreamWriter out = new UTF8StreamWriter().setOutput(bytesOut)) {
101+
BytesStream bytesOut = Streams.flushOnCloseStream(channel.bytesOutput());
102+
try (OutputStreamWriter out = new OutputStreamWriter(bytesOut, StandardCharsets.UTF_8)) {
100103
if (verbose) {
101104
for (int col = 0; col < headers.size(); col++) {
102105
DisplayHeader header = headers.get(col);
@@ -113,8 +116,8 @@ public static RestResponse buildTextPlainResponse(Table table, RestChannel chann
113116
}
114117
out.append("\n");
115118
}
116-
return new RestResponse(RestStatus.OK, RestResponse.TEXT_CONTENT_TYPE, bytesOut.bytes());
117119
}
120+
return new RestResponse(RestStatus.OK, RestResponse.TEXT_CONTENT_TYPE, bytesOut.bytes());
118121
}
119122

120123
private static List<DisplayHeader> buildDisplayHeaders(Table table, RestRequest request) {
@@ -258,7 +261,7 @@ private static int[] buildWidths(Table table, RestRequest request, boolean verbo
258261
return width;
259262
}
260263

261-
public static void pad(Table.Cell cell, int width, RestRequest request, UTF8StreamWriter out) throws IOException {
264+
public static void pad(Table.Cell cell, int width, RestRequest request, OutputStreamWriter out) throws IOException {
262265
String sValue = renderValue(request, cell.value);
263266
int length = sValue == null ? 0 : sValue.length();
264267
byte leftOver = (byte) (width - length);

src/main/java/org/ansj/elasticsearch/plugin/AnalysisAnsjPlugin.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import org.elasticsearch.client.internal.Client;
1818
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
1919
import org.elasticsearch.cluster.node.DiscoveryNodes;
20-
import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders;
20+
import org.elasticsearch.cluster.routing.allocation.AllocationService;
2121
import org.elasticsearch.cluster.service.ClusterService;
2222
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
2323
import org.elasticsearch.common.settings.ClusterSettings;
@@ -54,7 +54,7 @@ public class AnalysisAnsjPlugin extends Plugin implements AnalysisPlugin, Action
5454
private static final Logger LOG = LogManager.getLogger();
5555

5656
@Override
57-
public Collection<Object> createComponents(Client client, ClusterService clusterService, ThreadPool threadPool, ResourceWatcherService resourceWatcherService, ScriptService scriptService, NamedXContentRegistry xContentRegistry, Environment environment, NodeEnvironment nodeEnvironment, NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver indexNameExpressionResolver, Supplier<RepositoriesService> repositoriesServiceSupplier, Tracer tracer, AllocationDeciders allocationDeciders) {
57+
public Collection<Object> createComponents(Client client, ClusterService clusterService, ThreadPool threadPool, ResourceWatcherService resourceWatcherService, ScriptService scriptService, NamedXContentRegistry xContentRegistry, Environment environment, NodeEnvironment nodeEnvironment, NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver indexNameExpressionResolver, Supplier<RepositoriesService> repositoriesServiceSupplier, Tracer tracer, AllocationService allocationService) {
5858
return Collections.singletonList(new AnsjElasticConfigurator(environment));
5959
}
6060

0 commit comments

Comments
 (0)