ShardDocumentIndexShardDocumentIndex

Шардированный дисковый индекс для больших объёмов и высокой нагрузки.

A sharded disk index for large volumes and heavy load.

В API-хосте с версии 9.0.47 вместо ShardDocumentIndex по умолчанию создаётся SegmentShardDocumentIndex; ShardDocumentIndex остаётся в формате Legacy.

Since 9.0.47 the API host creates SegmentShardDocumentIndex instead of ShardDocumentIndex by default; ShardDocumentIndex remains in the Legacy format.

  • 1 или 16 шардов (ShardSize.One / ShardSize.Sixteen); шард выбирается по MD5 от ExternalId.1 or 16 shards (ShardSize.One / ShardSize.Sixteen); the shard is picked by the MD5 of ExternalId.
  • Шарды загружаются и ищутся параллельно.Shards load and search in parallel.
  • Запись идёт через журнал; надёжность задаётся ShardDocumentIndex.Durability (Sync по умолчанию или Async).Writes go through a journal; durability is set by ShardDocumentIndex.Durability (Sync by default, or Async).
  • Подробности — в технических характеристиках.Details — in technical specifications.
C#
var field = "*";
var query = "(first & \"second and four* \") | title:(four* ~3 'one')";

var settings = new ShardSettings(Directory.GetCurrentDirectory(), "test", ShardSize.Sixteen);
var documentIndex = new ShardDocumentIndex(settings, new IndexWordSelector());
while (!documentIndex.IsReady)
{
    Thread.Sleep(500);
}

var searchService = new SearchServiceEngine(documentIndex);

var doc = new IndexDocument("ExternalId");
doc.Add("content".GetField("six first second four"));
doc.Add("title".GetField("one first second four"));

// filter fields
doc.Add("intValue".GetFilterField(10));
doc.Add("longValue".GetFilterField(22L));
doc.Add("dateValue".GetFilterField(DateTime.UtcNow));
doc.Add("float".GetFilterField(1f));

searchService.Index(new IndexDocument[] { doc });

var request = new SearchQueryRequest()
{
    Query = query.Parse(field),
    Field = field,
    ShowHighlight = true,
    Size = 20,
    // filter: intValue == 10 AND longValue > 21
    Filter = new FilterClause()
    {
        Condition = FilterCondition.Equal,
        Value = "intValue".GetFilterField(10),
        Next = new FilterClause()
        {
            Condition = FilterCondition.Great,
            Value = "longValue".GetFilterField(21L)
        }
    }
};
var result = searchService.Search(request);

Сравнение индексовIndex comparison

ИндексIndexХранениеStorageДля чегоUse caseЭкспортExport
MemoryDocumentIndexОперативная памятьRAMТесты, небольшие и временные наборыTests, small and temporary setsпотокstream
DiskDocumentIndexДиск, 1 шардDisk, 1 shardНебольшие и средние индексыSmall and medium indexesпотокstream
ShardDocumentIndexДиск, 1 или 16 шардовDisk, 1 or 16 shardsБольшие индексы, высокая нагрузкаLarge indexes, heavy loadв другой индексinto another index
FileDocumentIndexИндекс по файлуIndex over a fileЛоги и большие текстовые файлыLogs and large text files—
SegmentShardDocumentIndexДиск, сегменты, 1 или 16 шардов; по умолчанию в API-хостеDisk, segments, 1 or 16 shards; API host defaultБольшие индексы без хранения текста, BM25, сортировка по датеLarge indexes without stored text, BM25, date sorting—
SegmentDocumentIndexДиск, неизменяемые сегментыDisk, immutable segmentsТо же без шардThe same without shards—

Memory, Disk и ShardDocumentIndex хранят текст полей (подсветка, поля документа, фильтрующие поля); сегментные индексы — нет.

Memory, Disk and ShardDocumentIndex store field texts (highlights, document fields, filter fields); segment indexes do not.