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 ofExternalId. - Шарды загружаются и ищутся параллельно.Shards load and search in parallel.
- Запись идёт через журнал; надёжность задаётся
ShardDocumentIndex.Durability(Syncпо умолчанию илиAsync).Writes go through a journal; durability is set byShardDocumentIndex.Durability(Syncby default, orAsync). - Подробности — в технических характеристиках.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.