lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael McCandless <>
Subject Re: How can I use a byte array as a Lucene index field?
Date Wed, 23 Sep 2015 15:31:15 GMT
You are indexing your field as a StoredField which means it's not
actually indexed (just stored), so no query (nor IW.deleteDocument)
will ever be able to find it.

Try StringField instead ... in recent versions you can pass a BytesRef
value to that.

Mike McCandless

On Wed, Sep 23, 2015 at 10:17 AM, Larry White <> wrote:
> I'm using Lucene 4.10.3. (I plan to upgrade soon but need to fix an issue
> on this version today).
> I switched a Lucene index from using string document ids to byte arrays.
> The problem I'm having is that the system no longer finds documents by
> their id. I *suspect* this is because the lucene code is not doing an
> Array.equals(), but rather a standard equals(). This is the code to add the
> document:
>     Document doc = new Document();
>     byte[] key = indexData.getKey().toByteArray();
>     System.out.println(Arrays.toString(key));
>     doc.add(new StoredField(DOCUMENT_PRIMARY_KEY, new BytesRef(key)));
>     writer.addDocument(doc);
> And this is the code to delete the document. The delete fails because the
> document is not found (although it does exist in the index).
>     void prepareDelete(byte[] documentId) throws IOException {
>         System.out.println(Arrays.toString(documentId));
>         Term term =
>                 new Term(DOCUMENT_PRIMARY_KEY, new BytesRef(documentId));
>         writer.deleteDocuments(term);
>     }
> By comparing the output of the print statements, I've determined that the
> keys are the same (in the sense that they contain the same bytes), but they
> do not share identity.
> Thanks very much for any and all assistance.

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

View raw message