Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update a new field to existing document

Tags:

solr

is there possibility to update a new field to an existing document? For example: There is an document with several fields, e.g.

ID=99999
Field1:text
Field2:text

This document is already in the index, now I want to insert a new field to this document WITHOUT the old data:

ID=99999
Field3:text

For now, the old document will be deleted and a new document with the ID will be created. So if I now search for the ID 99999 the result will be:

ID=99999
Field3:text

I read this at the Solr Wiki

How can I update a specific field of an existing document?

I want update a specific field in a document, is that possible? I only need to index one field for >a specific document. Do I have to index all the document for this?

No, just the one document. Let's say you have a CMS and you edit one document. You will need to re-index this document only by using the the add solr statement for the whole document (not one field only).

In Lucene to update a document the operation is really a delete followed by an add. You will need >to add the complete document as there is no such "update only a field" semantics in Lucene.

So is there any solution for this? Will this function be implemented in a further version (I currently use 3.6.0). As a workaround, I thought about writing a script or an application, which will collect the existing fields, add the new field and update the whole document. But I think this will suffer performance. Do you have any other ideas?

Best regards

like image 795
Christian Lendel Avatar asked Aug 03 '12 08:08

Christian Lendel


People also ask

How do I manually update a field in Word?

Update all fields in a documentPress F9. If your document has tables with fields or formulas, you might need to select each table separately and press F9. Tip: To make sure that you don't forget to update your table of contents before you print the document, set Word to update fields automatically before printing.

How do I add a field to an existing document in Mongodb?

To add field or fields to embedded documents (including documents in arrays) use the dot notation. See example. To add an element to an existing array field with $addFields , use with $concatArrays .

How do you update an existing document?

Select the document you want to edit by clicking the document name. On the Document Details page, click EDIT / UPDATE. You can see this button at the top right corner of the page only if you have Document Edit Permission. On the Edit Document page, make your changes.

How do you update text fields in Word?

Updating fields To update a field manually, right-click the field and then click Update Field or press F9. To update all fields manually in the main body of a document, press Ctrl + A to select all and then press F9. Some fields in headers, footers or text boxes must be updated separately.

How do I add a field to an existing document in SOLR?

There is no effective difference between updating fields and insert new fields from the document side. You'll have to configure the field by using the schema api or schema. xml, if not running in schemaless mode (so unless you're prototyping, add the field first). The atomic update support is the way to go.

Does Word automatically update fields?

Some fields, such as page numbers, will automatically update when you preview your document. Many fields are set by default to update when you open a document but you can also set an option in Microsoft Word to update fields when you preview your file.


1 Answers

From Solr 4 onwards you can update a field in solr ....no need to reindex the entire indexes .... various modifiers are supported like ....

set – set or replace a particular value, or remove the value if null is specified as the new value add – adds an additional value to a list remove – removes a value (or a list of values) from a list removeregex – removes from a list that match the given Java regular expression inc – increments a numeric value by a specific amount (use a negative value to decrement)

example :

document

{
 "id": "1",
 "name" : "Solr"
 "views" : "2"
}

now update with

$ curl http://localhost:8983/solr/demo/update -d '
[
 {"id"         : "1",
  "author"   : {"set":"Neal Stephenson"},
  "views"   : {"inc":3},
  }
]' 

will result into

{
 "id": "1",
 "name" : "Solr"
 "views" : "5"
 "author" : "Neal Stephenson"
}
like image 195
kanishka vatsa Avatar answered Sep 28 '22 07:09

kanishka vatsa