Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update solr index?

Tags:

solr

When the user creates a document, I add the date to the solr index. Every time the data changes like edit or delete, do I have to reindex the whole data?

What does reindex mean in that case? When I do

$this->indexData(array(
        'id' => $pid,
        'title' => $data['titel']
));

for each document and do $solr->addDocuments, does it just overwrite already existing data?

I tried to reindex the whole index on add/delete/edit but after I delete a certain field its information still seems to be in the index.

Any ideas?

like image 980
UpCat Avatar asked Mar 11 '11 06:03

UpCat


1 Answers

When you index a document to solr, it will overwrite any existing document with the same <uniqueKey/> which is usually the id. So yes, it overwrites existing data.

When you want to change a single field of a document you will have to reindex the whole document, as solr does not support updating of a field only. So, when you delete a field, you will have to reindex the document without the field. This will overwrite the existing data. Dont forget to send a commit at the end.

With Solr 4 you can update a single field of a document. See Atomic_Updates

like image 85
morja Avatar answered Sep 17 '22 13:09

morja