Reputation: 8154
I have been searching for a way to implement a hook/callback/event in Solr in order to get notified when a document is added/updated/committed. Right now, I am thinking I might have to simply parse the logs, but it would be nice to be able to implement something as a module/plugin if it already exists. I have looked through the JavaDoc for 4.7, but I am not seeing anything. I saw RealTimeGet, but that seems to not be what I am looking for.
Are there any hooks available built-in to Solr, or am I going to have to roll-my-own using the logs to determine what has been changed in the index?
Upvotes: 3
Views: 2086
Reputation: 1537
You can create a custom update processor chain and create your own UpdateRequestProcessor in order to perform custom code for add/delete/commit/etc this also gives you access to the incoming request if you need it.
For additional information on the update processors and chains see their wiki page. These processors can be built by extending the abstract Java class and bundling the plugin as described in the Solr Plugins page, or alternatively you can write the implementation in javascript as described on the script update processor page.
Upvotes: 3
Reputation: 1165
You can run an executable on postCommit and use a timestamp field (like arun was suggesting) if need be
<!-- The RunExecutableListener executes an external command.
exe - the name of the executable to run
dir - dir to use as the current working directory. default="."
wait - the calling thread waits until the executable returns.
default="true"
args - the arguments to pass to the program. default=nothing
env - environment variables to set. default=nothing
-->
<!-- A postCommit event is fired after every commit
-->
<listener event="postCommit" class="solr.RunExecutableListener">
<str name="exe">snapshooter</str>
<str name="dir">solr/bin</str>
<bool name="wait">true</bool>
<!--
<arr name="args"> <str>arg1</str> <str>arg2</str> </arr>
<arr name="env"> <str>MYVAR=val1</str> </arr>
-->
</listener>
</updateHandler>
See the documentation
Upvotes: 2
Reputation: 11023
Here is one approach. You could define a timestamp
field for all your docs like this:
<field name="timestamp" type="date" indexed="true" stored="true" default="NOW" />
This will get updated automatically by Solr whenever you add/update docs. Then you can query your collection for documents with timestamp
in the last minute or some such interval.
Not sure if a better alternative exists though.
Upvotes: 1