我是新来的ElasticSearch。我必须将搜索查询从传输客户端迁移到resthighlevelclient。
下面是我需要迁移的传输客户端的代码。
SearchRequestBuilder searchRequestBuilder = Client.prepareSearch(elasticsearchIndex);
try {
searchRequestBuilder.
setQuery(generateBoolQuery(keyword))
.setFrom(0).setSize(100).setExplain(true)
.execute().actionGet();
} catch (Exception ex) {
LOGGER.debug(errorMessage, ex);
throw new BadKeywordFormatException("Keyword \'" + keyword + "\' has " + "Unsupported characters. ", ex);
}
I have written corresponding code as
SearchRequest searchRequest = new SearchRequest(elasticsearchIndex);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.query(generateBoolQuery(keyword));
searchSourceBuilder.from(0).size(100).explain(true);
searchRequest.source(searchSourceBuilder);
SearchResponse searchResponse;
try {
searchResponse = elasticsearchClient.search(searchRequest, RequestOptions.DEFAULT);
} catch (IOException e) {
LOGGER.debug(errorMessage, e);
throw new BadKeywordFormatException("Keyword \'" + keyword + "\' has " + "Unsupported characters. ", e);
}
请告诉我这个代码有什么问题?请帮助我正确的对应代码。
我正在附加执行此查询时获取的错误日志。
错误日志
Exception in thread "main" ElasticsearchStatusException[Elasticsearch exception [type=search_phase_execution_exception, reason=all shards failed]]
at org.elasticsearch.rest.BytesRestResponse.errorFromXContent(BytesRestResponse.java:177)
at org.elasticsearch.client.RestHighLevelClient.parseEntity(RestHighLevelClient.java:1727)
at org.elasticsearch.client.RestHighLevelClient.parseResponseException(RestHighLevelClient.java:1704)
at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1467)
at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1424)
at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:1394)
at org.elasticsearch.client.RestHighLevelClient.search(RestHighLevelClient.java:930)
================================================================================================
Suppressed: org.elasticsearch.client.ResponseException: method [POST], host [https://localhost:9200], URI [/index_name/_search?typed_keys=true&ignore_unavailable=false&expand_wildcards=open&allow_no_indices=true&ignore_throttled=true&search_type=query_then_fetch&batched_reduce_size=512&ccs_minimize_roundtrips=true], status line [HTTP/1.1 400 Bad Request]
{"error":{"root_cause":[{"type":"query_shard_exception","reason":"failed to create query: {\n \"bool\" : {\n \"filter\" : [\n {\n \"bool\" : {\n \"should\" : [\n {\n \"regexp\" : {\n \"name\" : {\n \"value\" : \"/\\\\b(?:\\\\d[ -]*?){13,16}\\\\b/\",\n \"flags_value\" : 65535,\n \"max_determinized_states\" : 10000,\n \"boost\" : 1.0\n }\n }\n }\n ],\n \"adjust_pure_negative\" : true,\n \"boost\" : 1.0\n }\n }\n ],\n \"adjust_pure_negative\" : true,\n \"boost\" : 1.0\n }\n}","index_uuid":"wPZPF4RH2gMlH","index":"index_name"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"index_name","node":"jKaYqlQwCHqlch","reason":{"type":"query_shard_exception","reason":"failed to create query: {\n \"bool\" : {\n \"filter\" : [\n {\n \"bool\" : {\n \"should\" : [\n {\n \"regexp\" : {\n \"name\" : {\n \"value\" : \"/\\\\b(?:\\\\d[ -]*?){13,16}\\\\b/\",\n \"flags_value\" : 65535,\n \"max_determinized_states\" : 10000,\n \"boost\" : 1.0\n }\n }\n }\n ],\n \"adjust_pure_negative\" : true,\n \"boost\" : 1.0\n }\n }\n ],\n \"adjust_pure_negative\" : true,\n \"boost\" : 1.0\n }\n}","index_uuid":"wPZPF4RH2gMlH","index":"index_name","caused_by":{"type":"illegal_argument_exception","reason":"expected ']' at position 25"}}}]},"status":400}
at org.elasticsearch.client.RestClient.convertResponse(RestClient.java:253)
at org.elasticsearch.client.RestClient.performRequest(RestClient.java:231)
at org.elasticsearch.client.RestClient.performRequest(RestClient.java:205)
at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1454)
提前谢谢
暂无答案!
目前还没有任何答案,快来回答吧!