Skip to content

Sort index by field - #6833

Draft
guilload wants to merge 1 commit into
mainfrom
guilload/sorted-splits-1
Draft

guilload wants to merge 1 commit into
mainfrom
guilload/sorted-splits-1

Conversation

@guilload

Copy link
Copy Markdown
Member

Description

Introduce ability to sort an index by a single field.

How was this PR tested?

Describe how you tested this PR.

Comment thread docs/configuration/index-config.md Outdated
Comment on lines +624 to +634
tag_fields: [service]

indexing_settings:
sort_fields: [service]
```

`sort_fields` accepts a list of mapped field names but currently rejects more than one entry.
A bare name sorts ascending; prefix it with `-` for descending order, for example
`sort_fields: [-service]`. An explicit `+` also means ascending. Nested paths and escaped dots
use the same syntax as other field references. Empty names and repeated direction prefixes are
rejected. The field must be indexed with the `raw` tokenizer and use a raw fast-field normalizer.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tag_fields should have been part of indexing_settings :/

Comment thread docs/configuration/index-config.md Outdated
first for `asc` and last for `desc`; an empty string is a distinct value. Equal values retain all
documents. Physical ordering does not change query result ordering.

Generation-zero splits are sorted during indexing. Compaction preserves the input order,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete this paragraph.

Comment thread docs/configuration/index-config.md Outdated
and are compacted separately. This setting does not repartition splits or select service-specific
output boundaries.

Physical field sorting cannot be combined with node-level document fingerprint clustering;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete this paragraph.

Comment thread docs/internals/sorting.md
a field name with a hyphen `-`.
The special value `_score` means sorting by score, it is also Descending by default.

The prefix parser is shared with `indexing_settings.sort_fields` through

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the parse be moved to quickwit-common?

Comment thread docs/internals/split-format.md Outdated
metadata and direct lineage needed to reconstruct its metastore record.

Splits may declare `sort_fields` in their metastore metadata and recovery entry. Each entry
records a field name, direction, and logical comparison type, for example

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
records a field name, direction, and logical comparison type, for example
records a field name, order, and type, for example

// but this will require work on tantivy.
let indexed_split = IndexedSplit {
split_attrs: SplitAttrs {
split_id: "test-split".into(),

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
split_id: "test-split".into(),
split_id: "test-split".to_string(),

.send_message(PackagedSplitBatch::new(
vec![PackagedSplit {
split_attrs: SplitAttrs {
split_id: "test-split".into(),

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
split_id: "test-split".into(),
split_id: "test-split".to_string(),

let split_scratch_directory_2 = TempDirectory::for_test();
let packaged_split_1 = PackagedSplit {
split_attrs: SplitAttrs {
split_id: "test-split-1".into(),

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
split_id: "test-split-1".into(),
split_id: "test-split-1".to_string(),

Explicit conversions via to_string() are better than implicit conversations via into. Apply this suggestion everywhere.

index_uid: pipeline_id.index_uid,
source_id: pipeline_id.source_id,
doc_mapping_uid,
sort_fields: Vec::new(),

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sort_fields should be known by know why can't we pass it directly and remove the garbage tantivy_sort_by_field, resolve_sort_fields, etc.?

/// Declaring a type here does not enable indexing configuration support for that type.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Serialize, Deserialize, utoipa::ToSchema)]
#[serde(rename_all = "lowercase")]
pub enum SortValueType {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rationalize with what already exists in quickwit-search (SortFieldType, etc.) so we can remove SortValueType, SplitSortFieldType, etc.

@guilload
guilload force-pushed the guilload/sorted-splits-1 branch from 0119e60 to 998682c Compare September 28, 2026 21:51

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant