lucene-solr-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Cario, Elaine" <>
Subject RE: [Solr Schema API] SolrJ Access
Date Tue, 08 Jul 2014 20:59:42 GMT

I just got this to work myself:

	public static final String DEFINED_FIELDS_API = "/schema/fields";
	public static final String DYNAMIC_FIELDS_API = "/schema/dynamicfields";
	// just get a connection to Solr as usual (the factory is mine - it will use CloudSolrServer
or HttpSolrServer depending on if we're using SolrCloud or not)
	SolrClient client = SolrClientFactory.getSolrClientInstance(CLOUD_ENABLED);
	SolrServer solrConn = client.getConnection(SOLR_URL, collection);
	SolrQuery query = new SolrQuery();
	if (dynamicFields)
	query.setParam("showDefaults", true);

	QueryResponse response = solrConn.query(query)

Then you've got to parse the response using NamedList etc.etc.

-----Original Message-----
From: Alessandro Benedetti [] 
Sent: Tuesday, July 08, 2014 5:54 AM
Subject: [Solr Schema API] SolrJ Access

Hi guys,
wondering if there is any proper way to access Schema API via Solrj.

Of course is possible to reach them in Java with a specific Http Request, but in this way,
using SolrCloud for example we become coupled to one specific instance ( and we don't want)

Code Example :

            HttpResponse httpResponse;
>             String url=this.solrBase+"/"+core+ 
> +fieldName;
>             HttpPut httpPut = new HttpPut(url);
>             StringEntity entity = new StringEntity(
>                     "{\"type\":\"text_general\",\"stored\":\"true\"}" ,
>                     ContentType.APPLICATION_JSON);
>              httpPut.setEntity( entity );
>              HttpClient client=new DefaultHttpClient();
>              response = client.execute(httpPut);

Any suggestion ?
In my opinion should be interesting to have some auxiliary method in SolrServer if it's not
there yet.



Benedetti Alessandro
Visiting card :

"Tyger, tyger burning bright
In the forests of the night,
What immortal hand or eye
Could frame thy fearful symmetry?"

William Blake - Songs of Experience -1794 England

View raw message