Apache Solr – Basic Commands

Apache Solr – Basic Commands ”; Previous Next Starting Solr After installing Solr, browse to the bin folder in Solr home directory and start Solr using the following command. [Hadoop@localhost ~]$ cd [Hadoop@localhost ~]$ cd Solr/ [Hadoop@localhost Solr]$ cd bin/ [Hadoop@localhost bin]$ ./Solr start This command starts Solr in the background, listening on port 8983 by displaying the following message. Waiting up to 30 seconds to see Solr running on port 8983 [] Started Solr server on port 8983 (pid = 6035). Happy searching! Starting Solr in foreground If you start Solr using the start command, then Solr will start in the background. Instead, you can start Solr in the foreground using the –f option. [Hadoop@localhost bin]$ ./Solr start –f 5823 INFO (coreLoadExecutor-6-thread-2) [ ] o.a.s.c.SolrResourceLoader Adding ”file:/home/Hadoop/Solr/contrib/extraction/lib/xmlbeans-2.6.0.jar” to classloader 5823 INFO (coreLoadExecutor-6-thread-2) [ ] o.a.s.c.SolrResourceLoader Adding ”file:/home/Hadoop/Solr/dist/Solr-cell-6.2.0.jar” to classloader 5823 INFO (coreLoadExecutor-6-thread-2) [ ] o.a.s.c.SolrResourceLoader Adding ”file:/home/Hadoop/Solr/contrib/clustering/lib/carrot2-guava-18.0.jar” to classloader 5823 INFO (coreLoadExecutor-6-thread-2) [ ] o.a.s.c.SolrResourceLoader Adding ”file:/home/Hadoop/Solr/contrib/clustering/lib/attributes-binder1.3.1.jar” to classloader 5823 INFO (coreLoadExecutor-6-thread-2) [ ] o.a.s.c.SolrResourceLoader Adding ”file:/home/Hadoop/Solr/contrib/clustering/lib/simple-xml-2.7.1.jar” to classloader …………………………………………………………………………………………………………………………………………………………………………………………………………… …………………………………………………………………………………………………………………………………………………………………………………………………. 12901 INFO (coreLoadExecutor-6-thread-1) [ x:Solr_sample] o.a.s.u.UpdateLog Took 24.0ms to seed version buckets with highest version 1546058939881226240 12902 INFO (coreLoadExecutor-6-thread-1) [ x:Solr_sample] o.a.s.c.CoreContainer registering core: Solr_sample 12904 INFO (coreLoadExecutor-6-thread-2) [ x:my_core] o.a.s.u.UpdateLog Took 16.0ms to seed version buckets with highest version 1546058939894857728 12904 INFO (coreLoadExecutor-6-thread-2) [ x:my_core] o.a.s.c.CoreContainer registering core: my_core Starting Solr on another port Using –p option of the start command, we can start Solr in another port, as shown in the following code block. [Hadoop@localhost bin]$ ./Solr start -p 8984 Waiting up to 30 seconds to see Solr running on port 8984 [-] Started Solr server on port 8984 (pid = 10137). Happy searching! Stopping Solr You can stop Solr using the stop command. $ ./Solr stop This command stops Solr, displaying a message as shown below. Sending stop command to Solr running on port 8983 … waiting 5 seconds to allow Jetty process 6035 to stop gracefully. Restarting Solr The restart command of Solr stops Solr for 5 seconds and starts it again. You can restart Solr using the following command − ./Solr restart This command restarts Solr, displaying the following message − Sending stop command to Solr running on port 8983 … waiting 5 seconds to allow Jetty process 6671 to stop gracefully. Waiting up to 30 seconds to see Solr running on port 8983 [|] [/] Started Solr server on port 8983 (pid = 6906). Happy searching! Solr ─ help Command The help command of Solr can be used to check the usage of the Solr prompt and its options. [Hadoop@localhost bin]$ ./Solr -help Usage: Solr COMMAND OPTIONS where COMMAND is one of: start, stop, restart, status, healthcheck, create, create_core, create_collection, delete, version, zk Standalone server example (start Solr running in the background on port 8984): ./Solr start -p 8984 SolrCloud example (start Solr running in SolrCloud mode using localhost:2181 to connect to Zookeeper, with 1g max heap size and remote Java debug options enabled): ./Solr start -c -m 1g -z localhost:2181 -a “-Xdebug – Xrunjdwp:transport = dt_socket,server = y,suspend = n,address = 1044” Pass -help after any COMMAND to see command-specific usage information, such as: ./Solr start -help or ./Solr stop -help Solr ─ status Command This status command of Solr can be used to search and find out the running Solr instances on your computer. It can provide you information about a Solr instance such as its version, memory usage, etc. You can check the status of a Solr instance, using the status command as follows − [Hadoop@localhost bin]$ ./Solr status On executing, the above command displays the status of Solr as follows − Found 1 Solr nodes: Solr process 6906 running on port 8983 { “Solr_home”:”/home/Hadoop/Solr/server/Solr”, “version”:”6.2.0 764d0f19151dbff6f5fcd9fc4b2682cf934590c5 – mike – 2016-08-20 05:41:37″, “startTime”:”2016-09-20T06:00:02.877Z”, “uptime”:”0 days, 0 hours, 5 minutes, 14 seconds”, “memory”:”30.6 MB (%6.2) of 490.7 MB” } Solr Admin After starting Apache Solr, you can visit the homepage of the Solr web interface by using the following URL. Localhost:8983/Solr/ The interface of Solr Admin appears as follows − Print Page Previous Next Advertisements ”;

Apache Solr – Querying Data

Apache Solr – Querying Data ”; Previous Next In addition to storing data, Apache Solr also provides the facility of querying it back as and when required. Solr provides certain parameters using which we can query the data stored in it. In the following table, we have listed down the various query parameters available in Apache Solr. Parameter Description q This is the main query parameter of Apache Solr, documents are scored by their similarity to terms in this parameter. fq This parameter represents the filter query of Apache Solr the restricts the result set to documents matching this filter. start The start parameter represents the starting offsets for a page results the default value of this parameter is 0. rows This parameter represents the number of the documents that are to be retrieved per page. The default value of this parameter is 10. sort This parameter specifies the list of fields, separated by commas, based on which the results of the query is to be sorted. fl This parameter specifies the list of the fields to return for each document in the result set. wt This parameter represents the type of the response writer we wanted to view the result. You can see all these parameters as options to query Apache Solr. Visit the homepage of Apache Solr. On the left-hand side of the page, click on the option Query. Here, you can see the fields for the parameters of a query. Retrieving the Records Assume we have 3 records in the core named my_core. To retrieve a particular record from the selected core, you need to pass the name and value pairs of the fields of a particular document. For example, if you want to retrieve the record with the value of the field id, you need to pass the name-value pair of the field as − Id:001 as value for the parameter q and execute the query. In the same way, you can retrieve all the records from an index by passing *:* as a value to the parameter q, as shown in the following screenshot. Retrieving from the 2nd record We can retrieve the records from the second record by passing 2 as a value to the parameter start, as shown in the following screenshot. Restricting the Number of Records You can restrict the number of records by specifying a value in the rows parameter. For example, we can restrict the total number of records in the result of the query to 2 by passing the value 2 into the parameter rows, as shown in the following screenshot. Response Writer Type You can get the response in required document type by selecting one from the provided values of the parameter wt. In the above instance, we have chosen the .csv format to get the response. List of the Fields If we want to have particular fields in the resulted documents, we need to pass the list of the required fields, separated by commas, as a value to the property fl. In the following example, we are trying to retrieve the fields − id, phone, and first_name. Print Page Previous Next Advertisements ”;