lucene-solr-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Shawn Heisey <apa...@elyograg.org>
Subject Re: Adding request parameters when using SolrCloudClient.add()
Date Tue, 30 Aug 2016 23:26:04 GMT
On 8/30/2016 3:28 PM, Brent P wrote:
> Using SolrJ, I'm trying to figure out how to include request parameters
> when adding a document with SolrCloudClient.add().
>
> Here is what I was doing when using HttpSolrClient instead of
> SolrCloudClient:
>
> HttpSolrClient client = new HttpSolrClient.Builder("
> http://hostname.com:8983/solr/corename")
>     .withHttpClient(HttpClientBuilder.create().build())
>     .build();
> client.getInvariantParams().set("param1_name", "param1_value");
> client.getInvariantParams().set("param2_name", "param2_value");
>
> SolrInputDocument sDoc = new SolrInputDocument();
> // Populate sDoc fields.
> UpdateResponse response = client.add(sDoc);
>
>
> SolrCloudClient doesn't appear to have any methods for adding parameters,
> so I'm not sure how I can do it. When doing reads, I add parameters to the
> SolrQuery object, but when adding a SolrInputDocument object, I don't have
> that option.
>
> The only thing I can think of is that maybe adding them as fields in the
> SolrInputDocument object would do the trick, but would that actually work
> the same?

Add any parameter needed to a request object and have the client process
the request.  In this code, "client" is any sort of SolrClient.

  String collection = "test";
  SolrInputDocument doc = new SolrInputDocument();
  // Build your document.
  UpdateRequest req = new UpdateRequest();
  req.add(doc);
  req.setParam("param1", "value1");
  return req.process(client, collection);

I stole most of this from the add methods in the source code for SolrClient.

Thanks,
Shawn


Mime
View raw message