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.

nction. When this expression is sent to the /stream handler, the /stream hander sees the daemon function<br />

and keeps it in memory where it will run at intervals. In this particular example, the daemon function will run the u<br />

pdate function every second. The update function is wrapping a topic function, which returns all new<br />

documents for a specific query. The update function will send the new documents to another collection to be<br />

indexed.<br />

The effect of this is to continuously push new documents that match a specific query into another collection.<br />

Custom push functions can be plugged in that push documents out of <strong>Solr</strong> and into other systems, such as Kafka<br />

or an email system.<br />

Push streaming can also be used for continuous background aggregation scenarios where aggregates are rolled<br />

up in the background at intervals and pushed to other <strong>Solr</strong> collections. Another use case is continuous<br />

background machine learning model optimization, where the optimized model is pushed to another <strong>Solr</strong><br />

collection where they can be integrated into queries.<br />

The /stream handler supports a small set commands for listing and controlling daemon functions:<br />

http://localhost:8983/collection/stream?action=list<br />

This command will provide a listing of the current daemon's running on the specific node along with there current<br />

state.<br />

http://localhost:8983/collection/stream?action=stop&id=daemonId<br />

This command will stop a specific daemon function but leave it resident in memory<br />

http://localhost:8983/collection/stream?action=start&id=daemonId<br />

This command will start a specific daemon function that has been stopped.<br />

http://localhost:8983/collection/stream?action=kill&id=daemonId<br />

This command will stop a specific daemon function and remove it from memory.<br />

Continous Pull Streaming<br />

The DaemonStream java class (part of the <strong>Solr</strong>j libraries) can also be embedded in a java application to provide<br />

continuous pull streaming. Sample code:<br />

StreamContext context = new StreamContext()<br />

<strong>Solr</strong>ClientCache cache = new <strong>Solr</strong>ClientCache();<br />

context.set<strong>Solr</strong>ClientCache(cache);<br />

Map topicQueryParams = new HashMap();<br />

topicQueryParams.put("q","hello"); // The query for the topic<br />

topicQueryparams.put("rows", "500"); // How many rows to fetch during each run<br />

topicQueryparams.put("fl", "id, "title"); // The field list to return with the<br />

documents<br />

TopicStream topicStream = new TopicStream(zkHost, // Host address for the<br />

zookeeper service housing the collections<br />

"checkpoints", // The collection to store<br />

the topic checkpoints<br />

"topicData", // The collection to query<br />

for the topic records<br />

"topicId", // The id of the topic<br />

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

414

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

Saved successfully!

Ooh no, something went wrong!