11.05.2016 Views

Apache Solr Reference Guide Covering Apache Solr 6.0

21SiXmO

21SiXmO

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

DocValues enabled.<br />

Sending Queries<br />

The SQL Interface provides a basic JDBC driver and an HTTP interface to perform queries.<br />

JDBC Driver<br />

The JDBC Driver ships with <strong>Solr</strong>J. Below is sample code for creating a connection and executing a query with<br />

the JDBC driver:<br />

Connection con = null;<br />

try {<br />

con = DriverManager.getConnection("jdbc:solr://" + zkHost +<br />

"?collection=collection1&aggregationMode=map_reduce&numWorkers=2");<br />

stmt = con.createStatement();<br />

rs = stmt.executeQuery("SELECT a_s, sum(a_f) as sum FROM collection1 GROUP BY a_s<br />

ORDER BY sum desc");<br />

while(rs.next()) {<br />

String a_s = rs.getString("a_s");<br />

double s = rs.getDouble("sum");<br />

}<br />

} finally {<br />

rs.close();<br />

stmt.close();<br />

con.close();<br />

}<br />

The connection URL must contain the zkHost and the collection parameters. The collection must be a valid<br />

<strong>Solr</strong>Cloud collection at the specified ZooKeeper host. The collection must also be configured with the /sql handl<br />

er. The aggregationMode and numWorkers parameters are optional.<br />

HTTP Interface<br />

<strong>Solr</strong> accepts parallel SQL queries through the /sql handler.<br />

Below is a sample curl command performing a SQL aggregate query in facet mode:<br />

curl --data-urlencode 'stmt=SELECT to, count(*) FROM collection4 GROUP BY to ORDER<br />

BY count(*) desc LIMIT 10'<br />

http://localhost:8983/solr/collection4/sql?aggregationMode=facet<br />

Below is sample result set:<br />

<strong>Apache</strong> <strong>Solr</strong> <strong>Reference</strong> <strong>Guide</strong> <strong>6.0</strong><br />

428

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!