异常问题:
Caused by: org.elasticsearch.index.query.QueryShardException: Failed to parse query [LOL: Uzi和Mlxg偶遇飞机故障, 二人被赶下飞机, Uzi句话暴露关系!] at org.elasticsearch.index.query.QueryStringQueryBuilder.doToQuery(QueryStringQueryBuilder.java:1042) ~[elasticsearch-5.6.9.jar!/:5.6.9] at org.elasticsearch.index.query.AbstractQueryBuilder.toQuery(AbstractQueryBuilder.java:96) ~[elasticsearch-5.6.9.jar!/:5.6.9] at org.elasticsearch.index.query.BoolQueryBuilder.addBooleanClauses(BoolQueryBuilder.java:444) ~[elasticsearch-5.6.9.jar!/:5.6.9] at org.elasticsearch.index.query.BoolQueryBuilder.doToQuery(BoolQueryBuilder.java:418) ~[elasticsearch-5.6.9.jar!/:5.6.9] at org.elasticsearch.index.query.AbstractQueryBuilder.toQuery(AbstractQueryBuilder.java:96) ~[elasticsearch-5.6.9.jar!/:5.6.9] at org.elasticsearch.index.query.QueryShardContext.lambda$toQuery$1(QueryShardContext.java:313) ~[elasticsearch-5.6.9.jar!/:5.6.9] at org.elasticsearch.index.query.QueryShardContext.toQuery(QueryShardContext.java:325) ~[elasticsearch-5.6.9.jar!/:5.6.9] at org.elasticsearch.index.query.QueryShardContext.toQuery(QueryShardContext.java:312) ~[elasticsearch-5.6.9.jar!/:5.6.9] at org.elasticsearch.search.SearchService.parseSource(SearchService.java:617) ~[elasticsearch-5.6.9.jar!/:5.6.9] at org.elasticsearch.search.SearchService.createContext(SearchService.java:485) ~[elasticsearch-5.6.9.jar!/:5.6.9] at org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:461) ~[elasticsearch-5.6.9.jar!/:5.6.9] at org.elasticsearch.search.SearchService.executeDfsPhase(SearchService.java:226) ~[elasticsearch-5.6.9.jar!/:5.6.9] at org.elasticsearch.action.search.SearchTransportService$5.messageReceived(SearchTransportService.java:332) ~[elasticsearch-5.6.9.jar!/:5.6.9] at org.elasticsearch.action.search.SearchTransportService$5.messageReceived(SearchTransportService.java:329) ~[elasticsearch-5.6.9.jar!/:5.6.9] at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:69) ~[elasticsearch-5.6.9.jar!/:5.6.9] at org.elasticsearch.transport.TransportService$7.doRun(TransportService.java:644) ~[elasticsearch-5.6.9.jar!/:5.6.9] at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:638) ~[elasticsearch-5.6.9.jar!/:5.6.9] at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) ~[elasticsearch-5.6.9.jar!/:5.6.9] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[na:1.8.0_172] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[na:1.8.0_172] ... 1 common frames omitted Caused by: org.elasticsearch.common.io.stream.NotSerializableExceptionWrapper: parse_exception: Cannot parse 'LOL: Uzi和Mlxg偶遇飞机故障, 二人被赶下飞机, Uzi句话暴露关系!': Encountered "<EOF>" at line 1, column 40. Was expecting one of: <BAREOPER> ... "(" ... "*" ... <QUOTED> ... <TERM> ... <PREFIXTERM> ... <WILDTERM> ... <REGEXPTERM> ... "[" ... "{" ... <NUMBER> ... <TERM> ... "*" ...
1.异常原因
在搜索的时候没有对搜索的内容进行转义。
String intro = infomationSearchReqVO.getIntro(); //转义特殊字符 String searchIntro = QueryParser.escape(intro);
官方文档上写的很清楚,获取一个被转义后的字符串。
escape public static String escape(String s)
Returns a String where those characters that QueryParser expects to be escaped are escaped by a preceding \.
返回一个String,其中QueryParser期望被转义的那些字符被前面的转义\
。