Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using POST HTTP method to read data from Solr using SolrJ

Tags:

java

solr

solrj

We are using the SolrJ client to query documents from Solr. The query that we are building is large and Solr is rejecting the query (with error response 414 URI Too Long).

However, I can directly call Solr's /query endpoint and post the query as the body using a POST request. Is there a way to do this using the SolrJ client?

like image 274
Amit Avatar asked Jul 12 '18 07:07

Amit


1 Answers

You can use post method in SolrJ using QueryRequest which has options to set HTTP methods.

public QueryResponse query(SolrQuery parameters){
        QueryResponse resp=null;
        try {
            QueryRequest queryRequest=new QueryRequest(parameters);
            queryRequest.setMethod(SolrRequest.METHOD.POST);
            NamedList nl=solrClient.request(queryRequest);
            resp=new QueryResponse(nl, solrClient);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return resp;
    }
like image 173
raghu777 Avatar answered Sep 29 '22 08:09

raghu777