Solr: how to delete a collection? - solr

I am using solr 4.9, not adding any additional shard, just use whatever default it comes with it. I have created a collection and tried to delete it by using the following api :
http://<host>/solr/admin/collections?action=DELETE&name=collectionName
but it returns error :
Solr instance is not running in SolrCloud mode
My Solr is not solrCloud, but how do I delete my collection?

Go to the solr folder and Do this..
bin/solr delete -c collection_name
and restart solr with
bin/solr restart

n.b. Tested against Solr 4.9, should work with newer versions.
curl -v http://localhost:8983/solr/admin/cores?action=UNLOAD&deleteInstanceDir=true&core=collectionName

You can delete the Solr Collection in two ways.
1) From the command prompt:
Launch the command prompt from where you have extracted the Apache Solr. Run the below Command
Solr\bin>solr delete -c My_Collection
2) From the Solr Admin Console:
/admin/collections?action=DELETE&name=collection
For more information about the Apache Solr Collection API.
Apache Solr Collection API

According to this guide (https://cwiki.apache.org/confluence/display/solr/Collections+API) this API is working only, when you are in a SolrCloud mode.
If you want to just delete core or just delete all docs in that core, take a look here - https://wiki.apache.org/solr/CoreAdmin

Or do this with the API instead:
http://localhost:8983/solr/admin/collections?action=DELETE&collection=collection1&shard=shard1&replica=core_node1

You can delete a collection in three ways in the recent versions of Solr.
You can delete the collection manually by using the bin/solr tool
You can delete the collection manually via Solr Admin
You can delete the collection by using the Collections API
You can delete the collection by using the V2 API
Deleting a collection using the bin/solr tool is simple. You go to your SOLR_HOME directory and you run:
bin/solr delete -c COLLECTION_NAME
To delete a collection using the Collections API you would run a command like this:
curl 'localhost:8983/solr/admin/collections?action=DELETE&name=COLLECTION_NAME'
Finally, to use the V2 API and delete a collection using it you would do the following:
curl -XDELETE 'http://localhost:8983/api/c/COLLECTION_NAME'
If you plan on removing the collection very rarely, you can do that manually. If that is something commonly used - for example with aliases and time-based data I would suggest using the V2 API as this is the newest one and will probably replace the old APIs at some point.

You could use curl
curl -X GET -H "Content-Type: application/json" "http://localhost:8983/solr/admin/cores?wt=json&action=UNLOAD&core=gettingstarted"
Where gettingstarted is the name of the core that you want to delete.
Please note that the above assumes that solr is running on port 8983.

Though Adam's response is correct, here's the documentation to help use it: https://lucene.apache.org/solr/guide/7_7/collections-api.html#delete
I got stuck on this one for a while and was only getting the invalid deleting of cores answer, which, I'm guessing used to work for collections, but does not in newer versions.

Related

SOLR CLOUD - Uploading LTR features

We have a SOLR Cloud cluster with 4 nodes. Collections are created with 4 shards and 2 replicas.
I was using REST endpoints (pointing to a single instance for all operations), to create feature(s) and model(s).
http://{{SOLRCLOUD-HOST}}:8983/solr/{{ACTIVE_INDEX_NAME}}/schema/feature-store
http://{{SOLRCLOUD-HOST}}:8983/solr/{{ACTIVE_INDEX_NAME}}/schema/model-store
When I execute REST endpoint to fetch the existing feature(s) and models(s)
http://{{SOLRCLOUD-HOST}}:8983/solr/{{ACTIVE_INDEX_NAME}}/schema/feature-store
http://{{SOLRCLOUD-HOST}}:8983/solr/{{ACTIVE_INDEX_NAME}}/schema/model-store
I see my feature/model created sometimes and the other times it says they don't exist.
At this point, when restart my cluster, thre GET calls always return the created features and models.
Couple of questions -
Like config sets, is there a way to upload features and models without using REST endpoint?
Is restart required after uploading features and models.
Should the feature/mode be executed against all collections in the cluster (assume I have more than one collection with the same data created for different purpose, plz don't ask why, I have them)
Are the features/models created available for collections created in the future with the same config set, I ask this question because the feature/model uploaded is seen inside the config set as - _schema_model-store.json and _schema_feature-store.json
Please advice. Thanks!
Did you find any answers?
I was stuck with feature-store not being available on all shards. Your suggestion of restarting solr helped. Is that the permanent solution?
To answer your Question #3:
You need to upload the features/models for each collection, since collection is part of the upload url, notice the "techproducts" in feature upload example from solr doc:
curl -XPUT 'http://localhost:8983/solr/techproducts/schema/feature-store' --data-binary "#/path/myFeatures.json" -H 'Content-type:application/json'
Just reload the collection to make the feature and model json file to be available on all shards of the collection. The restart of solr is not required.

Solr: change managed schema to schema and add new field in WINDOWS when using DIH

I am trying to learn and create SOLR search engine for text search.
My initial step is to load a table of content from SQL to Solr. I have imported data using data import handler but Solr loaded only id field. Later I realised that the managed schema does not work with DIH. So I am currently switching form managed schema to classic schema.
One of the step that Solr learning material asks me to do is add new field through schema API and it has given below commands for UNIX. I am not sure its equivalent windows command. Since POST command cannot be used in windows.
curl -X POST -H 'Content-type:application/json' --data-binary '{
"add-field":{
"name":"sell-by",
"type":"tdate",
"stored":true
}
}' http://localhost:8983/solr/gettingstarted/schema
Below is the command I used which failed,
curl -X java -jar example\exampledocs\post.jar -H 'Content-type:application/json' --data-binary '{
"add-field":{
"name":"FIN",
"type":"int",
"stored":true
}
}' http://localhost:8983/solr/#/firstcore/schema
Your advice or help would be much appreciated. I am stuck here for long time. I could not find how to add fields in windows. Any advice would be very much appreciated.
There are some problem with your request parameter.
First of all type integer not available by default if you are implemented it then it is fine.
You have not specified request HTTP method so it takes as GET while it require POST. I think you removed it after try requesting it by POST but it may end-up with Method Not Supported.
Above problem Method Not Supported is not because of POST method, it is because your URL was wrong, It should be http://localhost:8983/solr/firstcore/schema.
These are the problem which I find from your provided data and here is my example of adding field.
And Yes I am using Postman as a rest client
After success operation you will see you schema file of you collection will updated in Files menu on SOLR WebApp:
To check that:
Go to the WebApp
Select Collection
Click on Files
Go to your chema file.
Find your added field.

Solr with Zookeeper and own schema

I'm a newbie to SOLR and there's a problem I can't solve so far: When I'm starting SOLR cloud with Zookeeper I like to create a collection with a personal schema. However, SOLR only loads the default 'example-data-driven-schema'.
Any suggestion what I should do in order to put my defined schema to it?
In order to create a new collection with your own schema, you need to use zkCli.sh and SolrCloud Collection API.
In particular, you could:
a) upload in Zookeeper (using Solr zkCli) the configuration directory for your new collection, for instance in
<my_new_config>
Examples of Solr ZkCli commands to upload your changes in ZooKeeper can be found here.
In particular, if you want to upload your configuration directory on Zk, you can:
STEP 1) run the command:
./server/scripts/cloud-scripts/zkcli.sh -zkhost 127.0.0.1:9983 \   -cmd upconfig -confname my_new_config -confdir server/solr/configsets/basic_configs/conf
STEP 2) Restart your Solr nodes so they can pick up the configuration changes.
Please remember that if you wish to replace an existing file in Zk you will need to use zkCli.sh clear to delete the existing one from ZooKeeper and then the putfile command to add the new one.
b) call the following API from your browser:
/admin/collections?action=CREATE&name=<my_collection_name>&collection.configName=<my_new_config>

Create Solr core in console with authentication

I have a Solr core that needs an authentication. Let's say I have a user with password password.
When I now try to create a Solr core in the console with
bin\solr create -c test
I get an HTTP Error 401.
Of course I need to specify my user. How can I add my user and password in the console?
Something like bin\solr create -c test -authentication user:password
Using Command Line scripts with BasicAuth
Add the following line to the (/opt/solr/bin) solr.in.sh or solr.in.cmd file. This example tells the bin/solr command line to to use "basic" as the type of authentication, and to pass credentials with the user-name "solr" and password "SolrRocks":
SOLR_AUTH_TYPE="basic"
SOLR_AUTHENTICATION_OPTS="-Dbasicauth=solr:SolrRocks"
look:
https://lucene.apache.org/solr/guide/6_6/basic-authentication-plugin.html#BasicAuthenticationPlugin-UsingBasicAuthwithSolrJ
If you use Basic Authentication than first set in the CMD Console:
set SOLR_AUTH_TYPE=basic
set SOLR_AUTHENTICATION_OPTS="-Dbasicauth=USER:PASS"
Customize USER:PASS for your need
It has been a while so, I am not sure if you still have this issue. But this can help others who may come across this like how I did.
I am new to solr, so there could be a better way of doing this than what I have here.
Are you using zookeeper for authentication?
Assuming you are using zookeeper for authentication
First of all, I checked and I don't think there is an -authentication parameter for solr create command.
So, this is how I hacked around this issue:
Stopped solr
Started solr without zookeeper
created the core like how you tried for the test core
Then uploaded configuration of the test core to zookeeper. I followed this document - https://systemsarchitect.net/2013/04/06/painless-guide-to-solr-cloud-configuration/
Restarted zookeeper server
Started solr with -p 8983 -z zookeeper_hostname:zookeeper_port
You should be able to access your test core with authentication enabled

Solr Cloud : no servers hosting shard

We have a cluster of standalone Solr cores (Solr 4.3) for which we had built some custom plugins. I'm now trying to prototype converting the cluster to a Solr Cloud cluster. This is how I am trying to deploy the cores (in 4.7.2).
Start solr with zookeeper embedded.
java -DzkRun -Djetty.port=8985 -jar start.jar
upload a config into Zookeeper (same config as the standalone cores)
zkcli.bat -zkhost localhost:9985 -cmd upconfig -confdir myconfig -confname myconfig
Create a new collection (mycollection) of 2 shards using the Collections API
http://localhost:8985/solr/admin/collections?action=CREATE&name=mycollection&numShards=2&replicationFactor=1&maxShardsPerNode=2&collection.configName=myconfig
So at this point I have two shards under my solr directory with the appropriate core.properties
But when I go to http://localhost:8985/solr/#/~cloud, I see that the two shards' status is "Down" when they are supposed to be active by default.
And when I try to index documents in them using SolrJ (via CloudSolrServer API) , I get the error "No live SolrServers available to handle this request". I restarted Solr but same issue.
private CloudSolrServer cloudSolr;
cloudSolr = new CloudSolrServer(zkHOST);
cloudSolr.setZkClientTimeout(zkClientTimeout);
cloudSolr.setDefaultCollection(collectionName);
cloudSolr.connect();
cloudSolr.add(doc)
What am I doing wrong? I did a lot of digging around and saw an old Jira bug saying that Solr Cloud shards won't be active until there are some documents in the index. If that is the reason, that's kind of like a catch-22 isn't it?
So anyways, I also tried adding some test documents manually and committed to see if things improved. Now on the shard statistics page, it correctly gives me the Numdocs count but when I try to query it says "no servers hosting shard". I next tried passing in shards.tolerant=true as a query parameter and search, but no cigar. It says 0 documents found.
Any help would be appreciated. My main objective is to rebuilt the old standalone cores using SolrCloud and test to see if our custom requesthandlers still work as expected. And at this point, I can't index documents inside of the 4.7 Solr Cloud collection I have created.
Thanks and Regards

Resources