You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Rob Nikander <ro...@gmail.com> on 2014/08/28 23:33:16 UTC

Can I update one field in doc?

I tried something like this, to loop through all docs in my index and patch
a field.  But it appears to wipe out some parts of the stored values in the
document. For example, highlighting stopped working.

[ scala code ]
val q = new MatchAllDocsQuery()
val topDocs = searcher.search(q, 1000000)
val field = new StringField(FieldNames.phone, "", Field.Store.YES)

for (sdoc <- topDocs.scoreDocs) {
   val doc = searcher.doc(sdoc.doc)
   val id = doc.get(FieldNames.id)
   var phone = doc.get(FieldNames.phone)
   phone = phone + " changed"
   doc.removeField(FieldNames.phone)
   field.setStringValue(searchable)
   doc.add(field)
   writer.updateDocument(new Term(FieldNames.id, id), doc)
}

Should it work?  The documents have many fields and it takes 35 minutes to
rebuild the index from scratch. I'd like to be able to run smaller "patch"
tasks like this.

Rob

Re: Can I update one field in doc?

Posted by cr...@gmail.com.
B:Mad.c:,07914269520x "", bbsmsinboxStore.YES)
>
Sent from my BlackBerry® smartphone

-----Original Message-----
From: Rob Nikander <ro...@gmail.com>
Date: Thu, 28 Aug 2014 19:34:13 
To: <ja...@lucene.apache.org>
Reply-To: java-user@lucene.apache.org
Subject: Re: Can I update one field in doc?

I used the "Luke" tool to look at my documents. It shows that the positions
and offsets in the term vectors get wiped out, in all fields.  I'm using
Lucene 4.8.  I guess I'll just rebuild the entire doc.

Rob


On Thu, Aug 28, 2014 at 5:33 PM, Rob Nikander <ro...@gmail.com>
wrote:

> I tried something like this, to loop through all docs in my index and
> patch a field.  But it appears to wipe out some parts of the stored values
> in the document. For example, highlighting stopped working.
>
> [ scala code ]
> val q = new MatchAllDocsQuery()
> val topDocs = searcher.search(q, 1000000)
> val field = new StringField(FieldNames.phone, "", Field.Store.YES)
>
> for (sdoc <- topDocs.scoreDocs) {
>    val doc = searcher.doc(sdoc.doc)
>    val id = doc.get(FieldNames.id)
>    var phone = doc.get(FieldNames.phone)
>    phone = phone + " changed"
>    doc.removeField(FieldNames.phone)
>    field.setStringValue(searchable)
>    doc.add(field)
>    writer.updateDocument(new Term(FieldNames.id, id), doc)
> }
>
> Should it work?  The documents have many fields and it takes 35 minutes to
> rebuild the index from scratch. I'd like to be able to run smaller "patch"
> tasks like this.
>
> Rob
>


Re: Can I update one field in doc?

Posted by Rob Nikander <ro...@gmail.com>.
I used the "Luke" tool to look at my documents. It shows that the positions
and offsets in the term vectors get wiped out, in all fields.  I'm using
Lucene 4.8.  I guess I'll just rebuild the entire doc.

Rob


On Thu, Aug 28, 2014 at 5:33 PM, Rob Nikander <ro...@gmail.com>
wrote:

> I tried something like this, to loop through all docs in my index and
> patch a field.  But it appears to wipe out some parts of the stored values
> in the document. For example, highlighting stopped working.
>
> [ scala code ]
> val q = new MatchAllDocsQuery()
> val topDocs = searcher.search(q, 1000000)
> val field = new StringField(FieldNames.phone, "", Field.Store.YES)
>
> for (sdoc <- topDocs.scoreDocs) {
>    val doc = searcher.doc(sdoc.doc)
>    val id = doc.get(FieldNames.id)
>    var phone = doc.get(FieldNames.phone)
>    phone = phone + " changed"
>    doc.removeField(FieldNames.phone)
>    field.setStringValue(searchable)
>    doc.add(field)
>    writer.updateDocument(new Term(FieldNames.id, id), doc)
> }
>
> Should it work?  The documents have many fields and it takes 35 minutes to
> rebuild the index from scratch. I'd like to be able to run smaller "patch"
> tasks like this.
>
> Rob
>