Solr SPARQL Endpoint in Two Minutes

How to store and query RDF data in Solr? Let’s do that in 2 minutes / 5 steps!

Step #1: What we need?

  • A shell  (in case you are on the dark side of the moon, all steps can be easily done in Eclipse or whatever IDE)
  • Java 7 or higher
  • Apache Maven (3.x)
  • git 

Step #2: Checkout SolRDF

Open a shell and type the following:
					> cd /tmp
> git clone https://github.com/SeaseLtd/SolRDF.git solrdf-download

Step #3: Build and Run SolRDF

					> cd solrdf-download/solrdf 
> mvn clean install
> cd solrdf-integration-tests 
> mvn clean package cargo:run
The very first time you run this command a lot of things will be downloaded, Solr included. At the end you should see something like this:
					[INFO] Jetty 7.6.15.v20140411 Embedded started on port [8080] 
[INFO] Press Ctrl-C to stop the container...
Congrats! SolRDF is up and running!

Step #4: Add Some Data

Open another shell and type the following:
					> curl -v http://localhost:8080/solr/store/update/bulk?commit=true \
  -H "Content-Type: application/n-triples" \
  --data-binary \
Wait a moment and…ok! You’ve added (about) 5000 triples!

Step #5: Query

Open another shell and type the following:
					> curl "" \
  --data-urlencode "q=SELECT * WHERE { ?s ?p ?o } LIMIT 10" \
  -H "Accept: application/sparql-results+json"


> curl "" \
  --data-urlencode "q=SELECT * WHERE { ?s ?p ?o } LIMIT 10" \
  -H "Accept: application/sparql-results+xml"
Et voilà!

Leave a Reply

%d bloggers like this: