Situation
SAP Hybris works with Apache Solr to provide enhanced product search capabilities.
There are two Solr modes: indexing and search. In indexing mode, Hybris fetches new products from the database and sends them to Solr for indexing.
Complexity
This operation is quite expensive in terms of performance, since product data needs to be collected from different database tables. To change only one attribute in the Solr index, you need to fetch all the attributes and update the Solr document completely.
For example, you may want to store price information in the index to enable price range filtering. When the price changes, you need to fetch all the product attributes and update the whole Solr document using the standard out-of-the-box Solr indexer configuration. If the product price changes frequently, the indexing process is going to become a bottleneck.
Challenge
How can you make the update operation faster if the changes are minor? How can you update only one attribute in the Solr document?
Solution
Apache Solr in standalone mode has a simple and well-documented indexer interface. For example, if you need to update only the price attribute, you can make an HTTP request to the Solr server:
curl 'http://localhost:8983/solr/master_My_Product/update?commit=true' \
-H 'Content-type:application/json' \
-d '[{"id":"ElectronicsProductCatalog/Online/<PRODUCTCODE>",
"priceValue_usd_double":{"set":"1020.00"}}]'- master_My_Product is the name of the Solr core.
- ElectronicsProductCatalog is the name of the product catalog.
- <PRODUCTCODE> is the product code.
Another example updates the availability status:
curl 'http://localhost:8983/solr/master_My_Product/update?commit=true' \
-H 'Content-type:application/json' \
-d '[{"id":"ElectronicsProductCatalog/Online/<PRODUCTCODE>",
"inStockFlag_boolean":{"set":"false"}}]'© Rauf Aliev, June 2016