lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jjlarrea <>
Subject Re: How to rename fields in an index
Date Fri, 01 Feb 2008 07:30:05 GMT

Did anyone ever post a packaged solution for simple field renaming?  Since I
didn't see one, I offer (link below) a beanshell script 'fieldrename' which
uses the Lucene API to run through the segments, gather fieldnames, pass
then through a user-supplied regular-expression transformation, and rewrite
the .fnm file.  For example,

    fieldrename /path/to/index  ^Abstract$ Summary
        (renaming of a single field via exact match: Abstract -> Summary)
    fieldrename /path/to/index  Number Code
        (change substring within every fieldname: ProductNumber ->
ProductCode, etc.)

It does save the original .fnm files as .fnm.bak just in case, but caveat
emptor: Used incorrectly it can destroy a good index in a flash, so always
use on a backup index.

It works under Lucene 2.2 but has not been tested with 2.3, and it needs a
few more lines of code to work with compound-file indexes (which I'd be
happy to add if someone were actually interested in using it).
FYI I used beanshell rather than Java not only for rapid prototyping, but
also because it allows access to a non-public method in the Lucene API.

Go wild,
J.J. Larrea fieldrename 

Andrzej Bialecki wrote:
> wrote:
>> Dear Andrzej Bialecki
>> Can we change the field name in *.fnm directly by hand?
> Yes, but you need to be consistent about it, i.e. change it the same way 
> for every segment that the index consists of. Also, fnm files are binary 
> files, so you need to know the format (unless you preserve the length of 
> the name, e.g. "secret" -> "public", then you can do it with a binary 
> editor).

View this message in context:
Sent from the Lucene - Java Users mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message