deepak643  
                (Deepak)
               
                 
              
                  
                    November 9, 2018, 11:51pm
                   
                   
              1 
               
             
            
              Hi all, 
May be this question was asked before See actual JSON from SearchRequestBuilder  but I am completely new to the elastic search.
I am trying to find a way to convert the queryBuilder/searchSourceBuilder to a Json.
I am trying out the very basic "match_all" query like below:
    SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
    searchSourceBuilder.query(QueryBuilders.matchAllQuery());
    searchSourceBuilder.from(0); 
    searchSourceBuilder.size(5);
 
I need to send the "json" from this builder to the REST end point to grab the results. 
Please help me find out how can I convert the builder to json
Also, I am not able to find any examples on how to use SearchRequestBuilder to see if I can use the above mentioned link for my use case.
             
            
               
               
               
            
            
           
          
            
              
                dadoonet  
                (David Pilato)
               
              
                  
                    November 10, 2018,  7:24am
                   
                   
              2 
               
             
            
              SearchSourceBuilder ssb = new SearchSourceBuilder()
        .query(QueryBuilders.matchAllQuery())
        .from(0)
        .size(5);
logger.info("{}", ssb);
 
Gives:
08:23:42,017 INFO [f.p.t.e.t.i.ElasticsearchIT] {"from":0,"size":5,"query":{"match_all":{"boost":1.0}}}
 
So call ssb.toString() ?
             
            
               
               
               
            
            
           
          
            
              
                deepak643  
                (Deepak)
               
              
                  
                    November 10, 2018,  8:04am
                   
                   
              3 
               
             
            
              
Thanks for your reply. 
But I already tried that and its printing the object reference "org.elasticsearch.search.builder.SearchSourceBuilder@6e0be858"
             
            
               
               
               
            
            
           
          
            
              
                deepak643  
                (Deepak)
               
              
                  
                    November 10, 2018,  8:09am
                   
                   
              4 
               
             
            
              I wish I can get the query like that! 
Any settings you did at your side?
             
            
               
               
               
            
            
           
          
            
              
                dadoonet  
                (David Pilato)
               
              
                  
                    November 10, 2018,  9:57am
                   
                   
              5 
               
             
            
              I'm using 6.4.3 version. May be you are using an old one?
             
            
               
               
               
            
            
           
          
            
              
                deepak643  
                (Deepak)
               
              
                  
                    November 10, 2018,  6:19pm
                   
                   
              6 
               
             
            
              Excellent. I was using some old versioned jar looks like.
I changed it to 6.4.2 like you mentioned and its printing the query as below: 
-> {"from":0,"size":5,"query":{"match_all":{"boost":1.0}}}
Thank you @dadoonet . Appreciate you idea.
             
            
               
               
               
            
            
           
          
            
              
                system  
                (system)
                  Closed 
               
              
                  
                    December 8, 2018,  6:21pm
                   
                   
              7 
               
             
            
              This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.