Apache Solr Querying Data - Apache Solr

How to query the data from Apache Solr?

Apache Solr facilitates the option of querying back the stored data when required. Certail parameters are provided by Apache Solr to query the data stored. The various query parameters available in Apache Solr are:

This is the main query parameter of Apache Solr, documents are scored by their similarity to terms in this parameter.
This parameter represents the filter query of Apache Solr the restricts the result set to documents matching this filter.
The start parameter represents the starting offsets for a page results the default value of this parameter is 0.
This parameter represents the number of the documents that are to be retrieved per page. The default value of this parameter is 10.
This parameter specifies the list of fields, separated by commas, based on which the results of the query is to be sorted.
This parameter specifies the list of the fields to return for each document in the result set.
This parameter represents the type of the response writer we wanted to view the result.

All the parameters are options to query Apache Solr. On the home page left-hand side, click on the option Query, the fields for the parameters of a query are visible.

Query Parameter

Retrieving the Records

For instance, if there are 3 records in the core my_core, and a single particular record can be retrieved by passing the name and value pairs of the fields of a particular document. The record with the value of the field id can be retrieved by passing the name-value pair of the field as − Id:001 as value for the parameter q and execute the query.

Retrieving Records

In a similar fashion, by passing *:* as a value to the parameter q all the records from an index can be retrieved.

Retrieve All

Retrieving from the 2nd record

The records from the second record can be retrieved by passing 2 as a value to the parameter start, as shown in the following screenshot.

Retrieving from Next Record

Restricting the Number of Records

By specifying a value in the rows parameter, the number of records can be restricted. For instance, the total number of records in the result of the query can be restricted to 2 by passing the value 2 into the parameter rows, as shown in the following screenshot.

Restricting Number of Records

Response Writer Type

Response in required document type can be made available by selecting one from the provided values of the parameter wt.

Response Writer Type

In the above instance, .csv format is chosen to get the response.

List of the Fields

To have particular fields in the resulted documents, pass the list of the required fields, separated by commas, as a value to the property fl.

In the following example, the fields − id, phone, and first_name are retrieved.

List Fields

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Apache Solr Topics