Solr Admin Commands
Start
bin/solr start -e cloud
Stop all
bin/solr stop -all
Create a new collection with 2 shards and two repls
bin/solr create -c sites -s 2 -rf 2
Delete a collection
bin/solr delete -c sites
view schema
curl http://localhost:8983/solr/sites/schema/fields
Index Your Custom Data
Start the server and create a collection
First we need to start the Solr Server and crate a collection called sites
, using the commands above.
Prepare some JSON data to be indexed
the data file is called: solr-test.json
[{
"id":1,
"url":"https://calmops.com",
"name":"calmops",
"description": "web blog"
}, {
"id":2,
"url":"https://abcd.net",
"name":"ABCD",
"description": "a fast search engine"
}]
If you are using MongoDB, when exporting data from it, is has a _id
field rather than id
field, we need to change _id
to id
, how to finish this, please reference Import Data from MongoDB into Meilisearch
.
Create schema
We need to set three fields, name, description and url.
curl -X POST -H 'Content-type:application/json' --data-binary '{"add-field": {"name":"name", "type":"text_general", "multiValued":false, "stored":true}}' http://localhost:8983/solr/sites/schema
curl -X POST -H 'Content-type:application/json' --data-binary '{"add-field": {"name":"url", "type":"text_general", "multiValued":false, "stored":true}}' http://localhost:8983/solr/sites/schema
curl -X POST -H 'Content-type:application/json' --data-binary '{"add-field": {"name":"description", "type":"text_general", "multiValued":false, "stored":true}}' http://localhost:8983/solr/sites/schema
Add a _text_
copy field for searching all the above fields.
curl -X POST -H 'Content-type:application/json' --data-binary '{"add-copy-field" : {"source":"*","dest":"_text_"}}' http://localhost:8983/solr/sites/schema
Post(or index) the data
bin/post -c sites ~/data/backup/solr-test.json
Now you can search the data posted.
References
https://solr.apache.org/guide/solr/latest/getting-started/tutorial-films.html