Lucene's StoredField Data Type

Overview

The StoredField data type in Lucene is utilized for storing the original values of a field so that it can be later retrieved. This field type does not contribute to the document's searchable index, making it unsuitable for search queries.


Key Features

1. Purpose

  • What: Used for storing actual values.
  • Why: Useful for retrieving the original value when reading a document from the index, for displaying or for further post-processing.

2. Storage

  • What: Value is stored as-is.
  • Why: Allows for the exact, original value to be retrieved without any transformation or loss of information.

3. Usage

  • What: Suited for fields whose original values need to be retrieved.
  • Example: Storing and retrieving the lastModified timestamp for a document.

Code Example

Here's a code snippet to demonstrate how StoredField is added to a Lucene Document.

import org.apache.lucene.document.Document;
import org.apache.lucene.document.StoredField;

Document doc = new Document();
long lastModifiedTime = 1612137600L; // Example timestamp
doc.add(new StoredField("lastModifiedStored", lastModifiedTime));

Notes

If you want to use range queries on timestamp look at Lucene's LongPoint Data Type


Backlinks