Fork me on GitHub

Gin or Gist Indexes Edit on GitHub


See Exploring the Postgres Gin index for more information on the Gin index strategy within Postgresqsl.

To optimize a wider range of adhoc queries against the document JSONB, you can apply a Gin index to the JSON field in the database:


public class IndexExamples : MartenRegistry
{
    public IndexExamples()
    {
        // Add a gin index to the User document type
        For<User>().GinIndexJsonData();

        // Adds a basic btree index to the duplicated
        // field for this property that also overrides
        // the Postgresql database type for the column
        For<User>().Duplicate(x => x.FirstName, pgType: "varchar(50)");

        // Customize the index on the duplicated field
        // for FirstName
        For<User>().Duplicate(x => x.FirstName, configure: idx =>
        {
            idx.IndexName = "idx_special";
            idx.Method = IndexMethod.hash;
        });

        // Customize the index on the duplicated field
        // for UserName to be unique
        For<User>().Duplicate(x => x.UserName, configure: idx =>
        {
            idx.IsUnique = true;
        });
    }
}


Marten may be changed to make the Gin index on the data field be automatic in the future.