异常信息
org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1256)↵ ... 48 more↵ Caused by: org.elasticsearch.client.ResponseException: method
[POST], host [http://xxxxxxurl], URI [/xxxxxxxx/xxxxxxxx/_search?typed_keys=true&ignore_unavailable=false&expand_wildcards=open&allow_no_indices=true&sear
ch_type=query_then_fetch&batched_reduce_size=512], status line [HTTP/1.1 400 Bad
Request]↵{"error":{"root_cause":[{"type":"token_mgr_error","reason":"token_mgr_error:
Lexical error at line 1, column 5. Encountered: <EOF> after :
\"\""}],"type":"search_phase_execution_exception","reason":"all shards
failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"xxxxxxxx","node":"uIjzNu0rRJew8dZu-9nWwA","reason":
{"type":"query_shard_exception","reason":"Failed to parse query [as./]","index_uuid":"uuid","index":"xxxxxxxx","caused_by":{"type":"parse_exception","reason":"parse_exception: Cannot parse 'as./': Lexical error at line 1, column 5. Encountered: <EOF> after : \"\"","caused_by":{"type":"token_mgr_error","reason":"token_mgr_error: Lexical error at line 1, column 5. Encountered: <EOF> after : \"\""}}}}]},"status":400}↵ at org.elasticsearch.client.RestClient$1.completed(RestClient.java:540)↵ at
org.elasticsearch.client.RestClient$1.completed(RestClient.java:529)↵ at
org.apache.http.concurrent.BasicFuture.completed(BasicFuture.java:122)↵ at
org.apache.http.impl.nio.client.DefaultClientExchangeHandlerImpl.responseCompleted(Defaul
tClientExchangeHandlerImpl.java:181)↵ at
org.apache.http.nio.protocol.HttpAsyncRequestExecutor.processResponse(HttpAsyncRequestExecutor.java:448)↵ at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.inputReady(HttpAsyncRequestExecutor.java:338)↵ at org.apache.http.impl.nio.DefaultNHttpClientConnection.consumeInput(DefaultNHttpClientConnection.java:265)↵ at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:81)↵ at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:39)↵ at org.apache.http.impl.nio.reactor.AbstractIODispatch.inputReady(AbstractIODispatch.java:114)↵ at org.apache.http.impl.nio.reactor.BaseIOReactor.readable(BaseIOReactor.java:162)↵ at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:337)↵ at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:315)↵ at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:276)↵ at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:104)↵ at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:591)↵ ... 1 more↵"
重点是这句
{“type”:“token_mgr_error”,“reason”:“token_mgr_error: Lexical error at line 1, column 5. Encountered: after : “””}
我们在查询的时候包含特殊字符:“”文章来源:https://www.toymoban.com/news/detail-591269.html
所以为了避免搜索出错,我们需要对查询的字符串先进行转义文章来源地址https://www.toymoban.com/news/detail-591269.html
public static String escape(String s) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c == '\\' || c == '+' || c == '-' || c == '!' || c == '(' || c == ')' || c == ':'
|| c == '^' || c == '[' || c == ']' || c == '\"' || c == '{' || c == '}' || c == '~'
|| c == '*' || c == '?' || c == '|' || c == '&' || c == '/') {
sb.append('\\');
}
sb.append(c);
}
return sb.toString();
}
到了这里,关于ES搜索特殊字符异常Encountered: <EOF> after的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!