- I have created a CRUD application with Solr using for searching records and spring solr data is used to interact with Solr.
- when when the application starts up I add data to solr index.
After starting up I delete a record from the index via Spring
SolrCrudRepository
Below is the code for the Repository
public interface SolrRentRepository extends SolrCrudRepository<SolrRent, String> { SolrRent findById(String id, Sort sort); List<SolrRent> findAll(Sort sort); }
Below is the
delete
function for deleting solr documentspublic void unindexRent(Rent rent) { if (rent == null || rent.getId() == null) { LOGGER.error("Invalid Rent object to unindex : " + String.valueOf(rent)); throw new RentsException("Invalid Rent object to unindex : " + String.valueOf(rent)); } rentRepository.delete(rent.getId()); LOGGER.info("Unindexed rent : " + rent); }
When I search the index After deleting, the deleted record appears.
If I insert a record using the application and delete it right after that, then the record doesn't reappear in the index.
Below is the solr document that I'm trying to delete.
public class SolrRent { @Field private String id; @Field private String city; @Field private String province; @Field private String country; @Field private String type; @Field(value = "airCondition") private boolean hasAirCondition; @Field(value = "garden") private boolean hasGarden; @Field(value = "pool") private boolean hasPool; @Field private boolean closeToBeach; @Field private double dailyPrice; @Field private int roomsNumber; @Field private Date lastModified; // getters & setters }
Solr
schema.xml
<?xml version="1.0" encoding="UTF-8" ?> <schema name="rents" version="1.5"> <types> <fieldType name="string" class="solr.TextField" sortMissingLast="true"> <analyzer> <tokenizer class="solr.KeywordTokenizerFactory"/> <filter class="solr.LowerCaseFilterFactory"/> </analyzer> </fieldType> <fieldType name="boolean" class="solr.BoolField" /> <fieldType name="double" class="solr.TrieDoubleField" sortMissingLast="true"/> <fieldType name="int" class="solr.TrieIntField" sortMissingLast="true"/> <fieldType name="date" class="solr.TrieDateField" precisionStep="0" positionIncrementGap="0"/> </types> <fields> <field name="id" type="string" indexed="true" stored="true" required="true"/> <field name="city" type="string" indexed="true" stored="true" required="true"/> <field name="province" type="string" indexed="true" stored="true" required="true"/> <field name="country" type="string" indexed="true" stored="true" required="true"/> <field name="type" type="string" indexed="true" stored="true" required="true"/> <field name="signatureField" type="string" stored="true" indexed="true" multiValued="false" /> <field name="airCondition" type="boolean" indexed="true" required="true"/> <field name="garden" type="boolean" indexed="true" required="true"/> <field name="pool" type="boolean" indexed="true" required="true"/> <field name="closeToBeach" type="boolean" indexed="true" required="true"/> <field name="dailyPrice" type="double" indexed="true" stored="true" required="true"/> <field name="roomsNumber" type="int" indexed="true" stored="true" required="true"/> <field name="lastModified" type="date" indexed="true" stored="true" required="true"/> <defaultSearchField>type</defaultSearchField> </fields> <uniqueKey>id</uniqueKey> </schema>
- solrconfig.xml
LUCENE_48 data native
<updateRequestProcessorChain name="deDupChain">
<processor class="solr.processor.SignatureUpdateProcessorFactory">
<bool name="enabled">true</bool>
<str name="signatureField">signatureField</str>
<bool name="overwriteDupes">true</bool>
<str name="fields">id</str>
<str name="signatureClass">solr.processor.Lookup3Signature</str>
</processor>
<processor class="solr.LogUpdateProcessorFactory" />
<processor class="solr.RunUpdateProcessorFactory" />
</updateRequestProcessorChain>
<query>
<maxBooleanClauses>1024</maxBooleanClauses>
<filterCache class="solr.FastLRUCache" size="512" initialSize="512" autowarmCount="0" />
<queryResultCache class="solr.LRUCache" size="512" initialSize="512" autowarmCount="0" />
<documentCache class="solr.LRUCache" size="512" initialSize="512" autowarmCount="0" />
<enableLazyFieldLoading>true</enableLazyFieldLoading>
<queryResultWindowSize>20</queryResultWindowSize>
<queryResultMaxDocsCached>200</queryResultMaxDocsCached>
<useColdSearcher>false</useColdSearcher>
<maxWarmingSearchers>2</maxWarmingSearchers>
</query>
<requestDispatcher handleSelect="false">
<requestParsers enableRemoteStreaming="true" multipartUploadLimitInKB="2048000" formdataUploadLimitInKB="2048" />
<httpCaching never304="true" />
</requestDispatcher>
<requestHandler name="/select" class="solr.SearchHandler" default="true">
<lst name="defaults">
<str name="sort">title asc</str>
<str name="echoParams">explicit</str>
<int name="rows">10</int>
<str name="q">*:*</str>
<bool name="facet">false</bool>
</lst>
</requestHandler>
<requestHandler name="/update" class="solr.UpdateRequestHandler" >
<lst name="defaults">
<str name="update.chain">deDupChain</str>
</lst>
</requestHandler>
<requestHandler name="/analysis/field" startup="lazy" class="solr.FieldAnalysisRequestHandler" />
<requestHandler name="/analysis/document" class="solr.DocumentAnalysisRequestHandler" startup="lazy" />
<requestHandler name="/admin/" class="solr.admin.AdminHandlers" />
<requestHandler name="/admin/ping" class="solr.PingRequestHandler">
<lst name="invariants">
<str name="q">*:*</str>
</lst>
<lst name="defaults">
<str name="echoParams">all</str>
</lst>
</requestHandler>
<admin>
<defaultQuery>*:*</defaultQuery>
</admin>
- pastebin link for the
schema.xml
andsolrconfig.xml
files - Solr version : 4.10.4
EDIT
- No manual commits were issued after inserting/deleting records.
- Below is the solr log that I get when I insert a record through the running app, search it and delete it immediately.
196228 [qtp1856056345-12] INFO org.apache.solr.update.processor.LogUpdateProcessor – [collection1] webapp=/solr path=/update params={wt=javabin&version=2} {delete=[31b31c84-9e91-45cc-9b41-f22facbf8157]} 0 1 196235 [qtp1856056345-12] INFO org.apache.solr.update.UpdateHandler – start commit{,optimize=false,openSearcher=true,waitSearcher=true,expungeDeletes=false,softCommit=false,prepareCommit=false} 197794 [qtp1856056345-12] INFO org.apache.solr.core.SolrCore – SolrDeletionPolicy.onCommit: commits: num=2 commit{dir=NRTCachingDirectory(MMapDirectory@/home/tharindu/Documents/apps/solr-4.10.4/example/solr/collection1/data/index lockFactory=NativeFSLockFactory@/home/tharindu/Documents/apps/solr-4.10.4/example/solr/collection1/data/index; maxCacheMB=48.0 maxMergeSizeMB=4.0),segFN=segments_d,generation=13} commit{dir=NRTCachingDirectory(MMapDirectory@/home/tharindu/Documents/apps/solr-4.10.4/example/solr/collection1/data/index lockFactory=NativeFSLockFactory@/home/tharindu/Documents/apps/solr-4.10.4/example/solr/collection1/data/index; maxCacheMB=48.0 maxMergeSizeMB=4.0),segFN=segments_e,generation=14} 197795 [qtp1856056345-12] INFO org.apache.solr.core.SolrCore – newest commit generation = 14 197796 [qtp1856056345-12] INFO org.apache.solr.search.SolrIndexSearcher – Opening Searcher@5fcf2379[collection1] main 197797 [qtp1856056345-12] INFO org.apache.solr.update.UpdateHandler – end_commit_flush 197797 [searcherExecutor-6-thread-1] INFO org.apache.solr.core.SolrCore – [collection1] Registered new searcher Searcher@5fcf2379[collection1] main{StandardDirectoryReader(segments_1:31:nrt _a(4.10.4):C10)} 197800 [qtp1856056345-12] INFO org.apache.solr.update.processor.LogUpdateProcessor – [collection1] webapp=/solr path=/update params={waitSearcher=true&commit=true&softCommit=false&wt=javabin&version=2} {commit=} 0 1565 203103 [qtp1856056345-12] INFO org.apache.solr.core.SolrCore – UnInverted multi-valued field {field=type,memSize=4476,tindexSize=48,time=0,phase1=0,nTerms=5,bigTerms=1,termInstances=7,uses=0} 203104 [qtp1856056345-12] INFO org.apache.solr.core.SolrCore – [collection1] webapp=/solr path=/select params={q=city:Badulla+AND+country:(Sri+Lanka)+AND+province:Uva&facet.limit=10&facet.field=type&sort=city+asc&facet.mincount=1&facet=true&wt=javabin&version=2} hits=0 status=0 QTime=18
- Below is the solr log when I try to search and delete a record that I've added on startup.
378758 [qtp1856056345-13] INFO org.apache.solr.core.SolrCore – [collection1] webapp=/solr path=/select params={q=city:city66&facet.limit=10&facet.field=type&sort=city+asc&facet.mincount=1&facet=true&wt=javabin&version=2} hits=2 status=0 QTime=6 383571 [qtp1856056345-13] INFO org.apache.solr.update.processor.LogUpdateProcessor – [collection1] webapp=/solr path=/update params={wt=javabin&version=2} {delete=[zZC8U]} 0 1 383578 [qtp1856056345-13] INFO org.apache.solr.update.UpdateHandler – start commit{,optimize=false,openSearcher=true,waitSearcher=true,expungeDeletes=false,softCommit=false,prepareCommit=false} 383745 [qtp1856056345-13] INFO org.apache.solr.core.SolrCore – SolrDeletionPolicy.onCommit: commits: num=2 commit{dir=NRTCachingDirectory(MMapDirectory@/home/tharindu/Documents/apps/solr-4.10.4/example/solr/collection1/data/index lockFactory=NativeFSLockFactory@/home/tharindu/Documents/apps/solr-4.10.4/example/solr/collection1/data/index; maxCacheMB=48.0 maxMergeSizeMB=4.0),segFN=segments_e,generation=14} commit{dir=NRTCachingDirectory(MMapDirectory@/home/tharindu/Documents/apps/solr-4.10.4/example/solr/collection1/data/index lockFactory=NativeFSLockFactory@/home/tharindu/Documents/apps/solr-4.10.4/example/solr/collection1/data/index; maxCacheMB=48.0 maxMergeSizeMB=4.0),segFN=segments_f,generation=15} 383745 [qtp1856056345-13] INFO org.apache.solr.core.SolrCore – newest commit generation = 15 383747 [qtp1856056345-13] INFO org.apache.solr.core.SolrCore – SolrIndexSearcher has not changed - not re-opening: org.apache.solr.search.SolrIndexSearcher 383747 [qtp1856056345-13] INFO org.apache.solr.update.UpdateHandler – end_commit_flush 383747 [qtp1856056345-13] INFO org.apache.solr.update.processor.LogUpdateProcessor – [collection1] webapp=/solr path=/update params={waitSearcher=true&commit=true&softCommit=false&wt=javabin&version=2} {commit=} 0 170 389109 [qtp1856056345-13] INFO org.apache.solr.core.SolrCore – [collection1] webapp=/solr path=/select params={q=city:city66&facet.limit=10&facet.field=type&sort=city+asc&facet.mincount=1&facet=true&wt=javabin&version=2} hits=2 status=0 QTime=5 Appreciate any help to resolve this issue.
@postConstruct
bean event listener method. Basically records are added in the same way at startup and after startup, as I have mentioned in the question. - No I didn't perform any commits and noautoCommit
config is added to thesolrconfig.xml
– tharindu_DG Oct 7 '16 at 1:17