Java – Solr – fields with default values reset themselves if store = false
When I set a field to stored = false and give it a default value, I encountered a strange problem with Solr (4. X) To make everything clear, my architecture is as follows:
<field name="field1" type="tint" indexed="true" stored="true" /> <field name="field2" type="tint" indexed="true" stored="true" /> <field name="field3" type="tint" indexed="true" stored="true" /> <field name="field4" type="tint" indexed="true" stored="true" /> <field name="field5" type="tint" indexed="true" stored="false" default="0" />
By default, there is a field5 = 0 at the beginning of each document Then I update the document and set field5 = 1 for some documents If I update the documents with field5 = 1, they all return to field5 = 0 However, when field5 stores = true, there is no problem. They will never return to the default value, although the field is not updated
Any solution to overcome this, I can certainly keep the field store = true, and then it will cause the index to become larger, which will slow down the search speed because of the overhead
Solution
Behind the scenes, the update operation retrieves the stored value of the field and re indexes the entire new entity Therefore, if a field is not marked as stored, it cannot be used with atomic updates Usually, unsaved fields disappear, and the interaction of default values is uncommon
I don't worry about the performance of this stage of index design, especially if it is digital You can use various optimizations later, and the bottleneck may not be what you expect