Indexes: Storing Data in Index

Once the tokenization and analysis process is completed, the resulting tokens, created according to the used analyzer, are stored in the index. By default, tokens saved in the index are available for searching. but their original field values aren't stored.

Lucene allows you to store the original field text (before it is analyzed) as well. This feature is exposed in the index definition object as the Storage property of the IndexFieldOptions.

Enabling field storing causes original values will be available for retrieval when doing projections.

public class Employees_ByFirstAndLastName : AbstractIndexCreationTask<Employee>
{
    public Employees_ByFirstAndLastName()
    {
        Map = employees => from employee in employees
                           select new
                           {
                               employee.FirstName,
                               employee.LastName
                           };

        Stores.Add(x => x.FirstName, FieldStorage.Yes);
        Stores.Add(x => x.LastName, FieldStorage.Yes);
    }
}
store
    .Maintenance
    .Send(new PutIndexesOperation(
        new IndexDefinition
        {
            Name = "Employees_ByFirstAndLastName",
            Maps =
            {
                @"from employee in docs.Employees
                  select new
                  {
                      employee.FirstName,
                      employee.LastName
                  }"
            },
            Fields = new Dictionary<string, IndexFieldOptions>
            {
                {"FirstName", new IndexFieldOptions
                              {
                                  Storage = FieldStorage.Yes
                              }
                },
                {"LastName", new IndexFieldOptions
                             {
                                Storage = FieldStorage.Yes
                             }
                }
            }
        }));

Remarks

Information

Default Storage value for each field is FieldStorage.No. Keep in mind that storing fields will increase disk space usage.

Info

If the projection requires only the fields that are stored, then the document will not be loaded from the storage and the query results will come directly from the index. This can increase query performance at the cost of disk space used.