我正在使用java执行ES查询:
query = 2bU: "70501" AND 2c2: <u>asasas</u>~
SearchResponse response = client.prepareSearch("XYZ")
.setTypes("MYTYPE")
.setQuery(QueryBuilders.queryString(query))
.setFrom((start-1)*.SEARCH_RESULT_PERPAGE).setSize(SEARCH_RESULT_PERPAGE)
.execute()
.actionGet();
SearchHit[] results = response.getHits().getHits();
这个<u>asasas</u>
的cos我得到了异常
Encountered: <EOF> after : "/u>~"]; nested: TokenMgrError[Lexical error at line 1,
column 37. Encountered: <EOF> after : "/u>~"];
这是完整的例外
org.elasticsearch.action.search.SearchPhaseExecutionException: Failed to execute phase [query], all shards failed; shardFailures {[Q702PZY9Ramp-_zZE4hNew][titan][0]: SearchParseException[[titan][0]: from[0],size[2]: Parse Failure [Failed to parse source [{"from":0,"size":2,"query":{"query_string":{"query":"2bU: \"70501\" AND 2c2: <u>asasas</u>~"}}}]]]; nested: QueryParsingException[[titan] Failed to parse query [2bU: "70501" AND 2c2: <u>asasas</u>~]]; nested: ParseException[Cannot parse '2bU: "70501" AND 2c2: <u>asasas</u>~': Lexical error at line 1, column 37. Encountered: <EOF> after : "/u>~"]; nested: TokenMgrError[Lexical error at line 1, column 37. Encountered: <EOF> after : "/u>~"]; }{[Q702PZY9Ramp-_zZE4hNew][titan][1]: SearchParseException[[titan][1]: from[0],size[2]: Parse Failure [Failed to parse source [{"from":0,"size":2,"query":{"query_string":{"query":"2bU: \"70501\" AND 2c2: <u>asasas</u>~"}}}]]]; nested: QueryParsingException[[titan] Failed to parse query [2bU: "70501" AND 2c2: <u>asasas</u>~]]; nested: ParseException[Cannot parse '2bU: "70501" AND 2c2: <u>asasas</u>~': Lexical error at line 1, column 37. Encountered: <EOF> after : "/u>~"]; nested: TokenMgrError[Lexical error at line 1, column 37. Encountered: <EOF> after : "/u>~"]; }{[Q702PZY9Ramp-_zZE4hNew][titan][2]: SearchParseException[[titan][2]: from[0],size[2]: Parse Failure [Failed to parse source [{"from":0,"size":2,"query":{"query_string":{"query":"2bU: \"70501\" AND 2c2: <u>asasas</u>~"}}}]]]; nested: QueryParsingException[[titan] Failed to parse query [2bU: "70501" AND 2c2: <u>asasas</u>~]]; nested: ParseException[Cannot parse '2bU: "70501" AND 2c2: <u>asasas</u>~': Lexical error at line 1, column 37. Encountered: <EOF> after : "/u>~"]; nested: TokenMgrError[Lexical error at line 1, column 37. Encountered: <EOF> after : "/u>~"]; }{[Q702PZY9Ramp-_zZE4hNew][titan][3]: SearchParseException[[titan][3]: from[0],size[2]: Parse Failure [Failed to parse source [{"from":0,"size":2,"query":{"query_string":{"query":"2bU: \"70501\" AND 2c2: <u>asasas</u>~"}}}]]]; nested: QueryParsingException[[titan] Failed to parse query [2bU: "70501" AND 2c2: <u>asasas</u>~]]; nested: ParseException[Cannot parse '2bU: "70501" AND 2c2: <u>asasas</u>~': Lexical error at line 1, column 37. Encountered: <EOF> after : "/u>~"]; nested: TokenMgrError[Lexical error at line 1, column 37. Encountered: <EOF> after : "/u>~"]; }{[Q702PZY9Ramp-_zZE4hNew][titan][4]: SearchParseException[[titan][4]: from[0],size[2]: Parse Failure [Failed to parse source [{"from":0,"size":2,"query":{"query_string":{"query":"2bU: \"70501\" AND 2c2: <u>asasas</u>~"}}}]]]; nested: QueryParsingException[[titan] Failed to parse query [2bU: "70501" AND 2c2: <u>asasas</u>~]]; nested: ParseException[Cannot parse '2bU: "70501" AND 2c2: <u>asasas</u>~': Lexical error at line 1, column 37. Encountered: <EOF> after : "/u>~"]; nested: TokenMgrError[Lexical error at line 1, column 37. Encountered: <EOF> after : "/u>~"]; }]
答案 0 :(得分:0)
在这里查看保留字符的部分: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html
在那里你可以发现/是一个需要转义的保留字符。请尝试以下方法:
<\/u>