You're right that "Update" is a little misleading as a name.
Solr uses that term across the board to refer to new or updated docs.
The "add-documents" API is /solr/collection_name/update and is
implemented by "UpdateRequestHandlers". You can configure Solr to
massage documents before indexing with a "UpdateRequestDocumentChain".
etc.
So the name is misleading, but at least it's consistent.
Best,
Jason
On Fri, Aug 10, 2018 at 10:52 PM ☼ R Nair wrote:
>
> Thanks Christoper and Jason. Problem solved. What you mentioned works.
>
> Thanks a million. Have a good weekend.
>
> Best,
> Ravion
>
> On Fri, Aug 10, 2018 at 3:31 PM Christopher Schultz <
> ch...@christopherschultz.net> wrote:
>
> > Ravion,
> >
> > What's wrong with "update request"? Updating a document that does not
> > exist... will add it.
> >
> > -chris
> >
> > On 8/10/18 3:01 PM, ☼ R Nair wrote:
> > > Do you feel that this is only partially complete?
> > >
> > > Best, Ravion
> > >
> > > On Fri, Aug 10, 2018, 1:37 PM ☼ R Nair
> > wrote:
> > >
> > >> I saw this. Please provide for add. My issue is with add. There is no
> > >> "AddRequesg". So how to do that, thanks
> > >>
> > >> Best Ravion
> > >>
> > >> On Fri, Aug 10, 2018, 12:58 PM Jason Gerlowski
> > >> wrote:
> > >>
> > >>> The "setBasicAuthCredentials" method works on all SolrRequest
> > >>> implementations. There's a corresponding SolrRequest object for most
> > >>> common Solr APIs. As you mentioned, I used QueryRequest above, but
> > >>> the same approach works for any SolrRequest object.
> > >>>
> > >>> The specific one for indexing is "UpdateRequest". Here's a short
> > example
> > >>> below:
> > >>>
> > >>> final List docsToIndex = new ArrayList<>();
> > >>> ...Prepare your docs for indexing
> > >>> final UpdateRequest update = new UpdateRequest();
> > >>> update.add(docsToIndex);
> > >>> update.setBasicAuthCredentials("solr", "solrRocks");
> > >>> update.process(client, "techproducts");
> > >>> On Fri, Aug 10, 2018 at 12:47 PM ☼ R Nair
> > >>> wrote:
> >
> > Hi Jason,
> >
> > Thanks for replying.
> >
> > I am adding a document, not querying. I am using 7.3 apis. Adding a
> > document is done via solrclient.add(). How to set authentication
> > in
> > this case? Seems I can't use SolrRequest.
> >
> > Thx, bye
> > RAVION
> >
> > On Fri, Aug 10, 2018, 10:46 AM Jason Gerlowski > >
> > wrote:
> >
> > > I'd tried to type my previous SolrJ example snippet from memory.
> > That
> > > didn't work out so great. I've corrected it below:
> > >
> > > final List zkUrls = new ArrayList<>();
> > > zkUrls.add("localhost:9983");
> > > final SolrClient client = new CloudSolrClient.Builder(zkUrls,
> > > Optional.empty()).build();
> > >
> > > final Map queryParamMap = new HashMap > >>> String>();
> > > queryParamMap.put("q", "*:*");
> > > final QueryRequest query = new QueryRequest(new
> > > MapSolrParams(queryParamMap));
> > > query.setBasicAuthCredentials("solr", "solrRocks");
> > >
> > > query.process(client, "techproducts"); // or, client.request(query)
> > > On Fri, Aug 10, 2018 at 10:12 AM Jason Gerlowski <
> > >>> gerlowsk...@gmail.com>
> > > wrote:
> > >>
> > >> I would also recommend removing the username/password from your Solr
> > >> base URL. You might be able to get things working that way, but
> > >>> it's
> > >> definitely less common, and it wouldn't surprise me if some parts of
> > >> SolrJ mishandle a URL in that format. Though that's just a hunch on
> > >> my part.
> > >> On Fri, Aug 10, 2018 at 10:09 AM Jason Gerlowski <
> > >>> gerlowsk...@gmail.com>
> > > wrote:
> > >>>
> > >>> Hi Ravion,
> > >>>
> > >>> (Note: I'm not sure what Solr version you're using. My answer
> > >>> below
> > >>> assumes Solr 7 APIs. These APIs don't change often, but you might
> > >>> find them under slightly different names in your version of Solr.)
> > >>>
> > >>> SolrJ provides 2 ways (that I know of) to provide basic auth
> > > credentials.
> > >>>
> > >>> The first (and IMO simplest) way is to use the
> > >>> setBasicAuthCredentials
> > >>> method on each individual SolrRequest. You can see what this
> > >>> looks
> > >>> like in the example below:
> > >>>
> > >>> final SolrClient client = new
> > >>>
> > >>> CloudSolrCLient.Builder(solrURLs).withHttpClient(myHttpClient).build();
> > >>> client.setDefaultCollection("collection1");
> > >>> SolrQuery req = new SolrQuery("*:*");
> > >>> req.setBasicAuthCredentials("yourUsername", "yourPassword);
> > >>> client.query(req);
> > >>>
> > >>> SolrJ also has a PreemptiveBasicAuthClientBuilderFactory, which
> > >>> reads
> > >>> the username/password from Java system properties, and is used to
> > >>> configure the HttpClient that SolrJ creates internally for sending
> > >