How to Query Data in a Solr Directory

Naduni Pamudika
API Integration Essentials
3 min readJul 24, 2019

Solr is the most popular, open source enterprise searching platform built on Apache Lucene [1].

Source: https://en.wikipedia.org/wiki/Apache_Solr

In WSO2 API Manager, it uses Solr indexing to keep the searching faster in APIM Store and Publisher. Solr indexing keeps the frequently used meta data of APIs and searching happens based on that indexed data in the Solr directory. Later on, it uses the databases to retrieve the complete information about an API, which makes the searching super fast since it doesn’t have to go through the whole set of data in the database while searching.

When there are issues in the APIM Publisher or Store, such as some indexing issues like a few APIs are missing in the UI, you can use the Solr data directory resides in the APIM server distribution (<APIM_Server_Home>/solr/data) to analyze the indexed data to see whether there are any issues.

In order to query the Solr data, you can use the Solr server [2]. Let’s see how you can query the data in detail below.

Prerequisites

  1. Download the Solr Server version 5.2.1 from [3]. WSO2 APIM uses the version 5.2.1 in APIM-2.6.0. You can find the used Solr version by looking at the registry version used in particular APIM release tag [4] and then from the found carbon-registry version’s pom.xml file [5].
  2. Extract the downloaded zip file.
  3. Copy the registry-indexing folder from <APIM_Server_Home>/repository/conf/solr/ folder to solr-5.2.1/server/solr directory to copy the relevant configs.
  4. Copy the <APIM_Server_Home>/solr directory to the same directory the extracted solr-5.2.1 folder resides.
  5. Make sure to have both the solr and solr-5.2.1 directories in the same location.

Querying Data

  • Navigate to /solr-5.2.1/bin directory and open a terminal from there.
  • Run ./solr start command to start the server. You can stop the server by executing ./solr stop command.
  • Access Solr admin console using the URL http://localhost:8983/solr/
  • From the left hand pane, select registry-indexing under Core Selector as shown below.
Registry-Indexing
  • Then select Query under registry-indexing.
Query
  • Now you can query the indexed data as below. You can put property:value pairs to fq and click Execute Query button. For an example, to retrieve all the APIs, you can use API media type as mediaType_s: “application/vnd.wso2-api+xml”
API Media Type Query
  • This will show the result set as below.
Results

Tips

  • By default, it will show only 10 entries. In order to retrieve more, you can set the value at start, rows section.
Giving a Range to Show Data
  • You can filter only a particular field by giving the field at fl. Here it show only the id filed in the entries of the result set.
Showing only Selected Fields

For more information regarding querying data, refer the documentations at [6], [7].

Hope you find this helpful. Happy Querying!

--

--

Naduni Pamudika
API Integration Essentials

Associate Technical Lead @ WSO2 | Graduate from the Department of Computer Science & Engineering, University of Moratuwa