Running basic Solr commands

Earlier, we started Solr in interactive mode, where we picked up the cloud as the default config set. Let's revisit the Solr startup commands.

If you want to start Solr with a custom port, then you can use the following command:

binsolr.cmd start -p 8984
Based on your operating system, you have to use bin/solr or binsolr.cmd.

Similar to start, there's a command stop. To stop Solr, simply use the following command:

binsolr.cmd stop -all

The -all parameter stops all Solr instances; if you want to stop a specific port, then pass that port number with an argument with parameter -p. Let's say you start Solr with any key; then you can stop that particular instance by passing the key as a parameter:

binsolr.cmd stop -k <key_name>

As seen earlier, you can launch examples by passing the -e flag:

binsolr.cmd -e <example_name>

Let's start Solr in cloud mode; hitting binsolr.cmd -e cloud will start the interactive process as follows:

  • Specifying the number of nodes on which we would like to run Solr in the local cluster
  • Port number for each Solr instance
  • Creating a Solr instance home directory with node 1, node 2, and node 3
  • Specifying the name for a new collection
  • Specifying the shards, the new collection should split
  • The replicas per shard we want to create
  • The configuration for collection which we want

After this, the config API will be called and updated with the selected configurations. Then you can see the Solr running status on hitting http://localhost:8983/solr/#/~cloud. It should show something like this:

Now, to check the status of the running instances of Solr, it provides the command status. Let's check out the number of Solr instances we have up and running:

binsolr.cmd status

The following screenshot is the output that shows the status of the Solr service, with a few more details such as uptime, solr_home, memory, and so on:

Now, if you haven't started Solr with example config sets, you will find no core created. Simply put, a core is just like a database in an SQL table. To create a new core at any time, just use the following command:

binsolr.cmd create -c <name>

This command essentially creates a core or collection based on whether Solr is running in standalone (core) mode or SolrCloud (collection) mode. Based on the running instance of Solr, this command does its action.

By default, any new core created follows the _default config set, which is not a recommended practice in production.

If you want to delete a collection, just invoke the following rest point:

 http://localhost:8983/solr/admin/collections?action=DELETE&name=<name_of_collection>

Now let's add some sample documents to our collection. I have some PDF documents on microservices and Node.js, and I am indexing in Solr. Open up your terminal.

If you are on Linux, hit the following command:

bin/post -c chintan <path_to_documents>/*.pdf

If you are on Windows, do this:

java -Dauto -Dc=chintan -jar post.jar E:\books\solr\chintan\*.pdf

In both cases, it looks for all the PDF documents in the folder, indexes them, and adds them into the collection or core: chintan.

If you want to use the post utility in Windows, download Cygwin and try the same command as in Linux.

Now that the documents are successfully indexed, let's verify by asking Solr questions. Open up the terminal and query collection getting started by asking questions about the query parameter nodejs by hitting the following end point, which would be http://localhost:8983/solr/gettingstarted/select?q=nodejs.

You should get a response like this:

{"responseHeader":{ "zkConnected":true, "status":0, "QTime":22, "params":{ "q":"nodejs"}}, "response":{"numFound":2,"start":0,"maxScore":2.283722,"docs":[ {},{}]
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.109.4