Home > Back-end >  Help RestHighLevelClient query ES, search method automatically compile full URL in 404
Help RestHighLevelClient query ES, search method automatically compile full URL in 404

Time:09-16

The code is as follows:

 
Public static void main (String [] args) throws the Exception {
The SearchRequest SearchRequest=new SearchRequest (" common/elasticsearch - test ");
The searchRequest. Types (" the frequent - appear ");
Int fromIndex=0;
Int pageSize=50;
The searchRequest. Source (new SearchSourceBuilder ()
The query (QueryBuilders. TermQuery (" id ", "1998"))
The from (fromIndex). The size (pageSize). Sort (" count "));
The SearchResponse response;
RestHighLevelClient RestHighLevelClient;
EsManager EsManager=new EsManager (" 192.168.120.12 ", 30000);
RestHighLevelClient=esManager. GetClient ();
The response=restHighLevelClient. Search (searchRequest);
System. The out. Println (response. GetHits () getHits (.) length);
RestHighLevelClient. Close ();
}


After joining together the full path to the right should be:
http://192.168.120.12:30000/common/elasticsearch-test/frequent-appear/_search? Typed_keys=true& Ignore_unavailable=false& Expand_wildcards=open& Allow_no_indices=true& Search_type=query_then_fetch & amp; Batched_reduce_size=512

But transformed to:
http://192.168.120.12:30000/common%2Felasticsearch-test/frequent-appear/_search? Typed_keys=true& Ignore_unavailable=false& Expand_wildcards=open& Allow_no_indices=true& Search_type=query_then_fetch & amp; Batched_reduce_size=512

The path of/transformed into % 2 f

CSDN the great god for help!

CodePudding user response:

 

RestHighLevelClient client=new RestHighLevelClient (
RestClient. Builder (
New HttpHost (IP, Integer. The valueOf (port), "HTTP")));

CodePudding user response:

reference 1st floor tianfang response:
 

RestHighLevelClient client=new RestHighLevelClient (
RestClient. Builder (
New HttpHost (IP, Integer. The valueOf (port), "HTTP")));


The above
EsManager EsManager=new EsManager (" 192.168.120.12 ", 30000);
RestHighLevelClient=esManager. GetClient ();
This code is inside this implementation
RestHighLevelClient client=new RestHighLevelClient (
RestClient. Builder (
New HttpHost (IP, Integer. The valueOf (port), "HTTP")));

CodePudding user response:

Replace without EsManager

CodePudding user response:

reference 4 floor tianfang response:
replace ah no EsManager


To the case:
The SearchRequest SearchRequest=new SearchRequest (" common/elasticsearch - test ");
The searchRequest. Types (" the frequent - appear ");
Int fromIndex=0;
Int pageSize=50;
The searchRequest. Source (new SearchSourceBuilder ()
The query (QueryBuilders. TermQuery (" id ", "1998"))
The from (fromIndex). The size (pageSize). Sort (" count "));
RestHighLevelClient RestHighLevelClient=new RestHighLevelClient (RestClient. Builder (new HttpHost (" 192.168.120.12 ", 30000, "HTTP")));
RestHighLevelClient=esManager. GetClient ();
The SearchResponse response=restHighLevelClient. Search (searchRequest);
System. The out. Println (response. GetHits () getHits (.) length);
RestHighLevelClient. Close ();
But in the implementation. The search () method will take path of/automatically converted to % 2 f 404 error!
More strange is the main way to run can be alone, but not in project, I watched the breakpoint source, the difference is:
The main method in performing this step Request the req=requestConverter. Apply (Request); Way to request into a GET request,
Code and project execution to this step will be converted into a POST request, what reason is this?

CodePudding user response:

reference 5 floor Nuncleh reply:
Quote: refer to 4th floor tianfang response:
replace ah no EsManager


To the case:
The SearchRequest SearchRequest=new SearchRequest (" common/elasticsearch - test ");
The searchRequest. Types (" the frequent - appear ");
Int fromIndex=0;
Int pageSize=50;
The searchRequest. Source (new SearchSourceBuilder ()
The query (QueryBuilders. TermQuery (" id ", "1998"))
The from (fromIndex). The size (pageSize). Sort (" count "));
RestHighLevelClient RestHighLevelClient=new RestHighLevelClient (RestClient. Builder (new HttpHost (" 192.168.120.12 ", 30000, "HTTP")));
RestHighLevelClient=esManager. GetClient ();
The SearchResponse response=restHighLevelClient. Search (searchRequest);
System. The out. Println (response. GetHits () getHits (.) length);
RestHighLevelClient. Close ();
But in the implementation. The search () method will take path of/automatically converted to % 2 f 404 error!
More strange is the main way to run can be alone, but not in project, I watched the breakpoint source, the difference is:
The main method in performing this step Request the req=requestConverter. Apply (Request); Way to request into a GET request,
Code and project execution to this step will be converted into a POST request, what reason is this?


Try to remove the line
RestHighLevelClient=esManager. GetClient ();

CodePudding user response:

To remove or not
Is still the same error, mian method can, in the project as an error 404??
  • Related