Skip to content

Rank an API operation first when the query is its whole title - #4908

Merged
reakaleek merged 4 commits into
mainfrom
fix-create-index-api-sear-c77679e8
Nov 17, 2026
Merged

reakaleek merged 4 commits into
mainfrom
fix-create-index-api-sear-c77679e8

Conversation

@reakaleek

Copy link
Copy Markdown
Member

API search now ranks an operation first when the typed words are its whole title, whatever their order and without the title's stopwords or plurals. create index finds "Create an index" first, where it used to list it eighth.

Affects: Search, API reference

Prompt summary: Fix the API search result for create index, where the "Create an index" operation sat seventh and showed only after scrolling. Then make sure the ranking work done earlier keeps working, with tests that fail when a later change moves it.

Why

create index lists "Create a new document in the index" first and "Create an index" eighth. The word create is the _create endpoint of the document operation, which scores 6.0 on its own, while PUT /{index} has no endpoint key. The only whole-title signal is an exact match on title.keyword, and the "an" in the title defeats it. delete index has the same shape: "Delete indices" lists twelfth.

What

A title that matches by its words

Each operation indexes its title as api.title_fingerprint, one token of the title's stemmed content words in sorted order. A query made of those words earns a 6.0 title_named lift. The lift replaces the exact-title term, which stays as the first option of the same dis_max, so an index without the new field keeps matching exact titles.

The analyzer behind it

title_fingerprint_analyzer runs standard, lowercase, english_stop, a stemmer override for indices => index, kstem and fingerprint. It sits in the shared base analysis next to the other analyzers some document types do not use. The override is private to this analyzer, so docs-wide search does not change.

Judged cases that lock earlier tuning

Eight judged cases and a landing-page test pin behaviour that lived only in ApiLookupWeights comments, such as the current HEAD /_template/{name} above its deprecated twins. They pass on the code before this fix. The failing create index, index create and delete index cases land in their own commit, ahead of the fix.

A report you can diff

The explicit ApiSearchRelevanceReport now also lists queries with no expected result and writes its output to API_SEARCH_REPORT_PATH. A run before and a run after a change can be diffed.

Verify

Measured on the dev index after a rollover:

Query Before After
create index operation-create first, 11.20 "Create an index" first, 13.13
delete index a Kibana operation first, 8.08 "Delete indices" first, 13.13

The controls search knn, cluster health, snapshot restore and get cluster settings keep their order and margins. Across 82 queries the top three changed mostly through Stack and Serverless ties, plus gains such as reassign agent. run a search loses 2.1 points and keeps its order.

dotnet test --project tests/Elastic.Documentation.Api.Tests
dotnet test --project tests/Elastic.ApiExplorer.Tests
# needs a dev index that has been re-indexed with this change
ENVIRONMENT=dev dotnet test --project tests-integration/Search.IntegrationTests/ --treenode-filter "/*/*/SearchRelevanceTests/ApiSearch*"

The integration cases are not run in CI, because the integration job in ci.yml is disabled. One case, ApiSearchPlainWordDoesNotCoverTheRoutesUnderItsOwnName, also fails on main with Kibana results for api key.

Risk: The field is new on every API document, so the next indexing run changes every API document hash and rolls the index over to the new mapping. Until an environment's index rolls over, create index behaves as before.

Out of scope: get index still lists get-index-template first because its title is "Get index information", and create index template still leads with a deprecated operation.

🤖 Generated with Claude Code

reakaleek and others added 4 commits November 17, 2026 19:29
Several tuned behaviours lived only in the `ApiLookupWeights` comments: the current `HEAD /_template/{name}` above its deprecated twins, the endpoint isolate pair, and a landing page leading for the words of its name. Eight judged cases and one landing test now pin them, so a weight change that moves one fails a test.

The explicit `ApiSearchRelevanceReport` also lists queries with no expected result and writes its output to `API_SEARCH_REPORT_PATH`, so a run before and a run after a change can be diffed.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
`create index` lists "Create a new document in the index" first and "Create an index" eighth. The `_create` endpoint scores 6.0 for the word `create`, while `PUT /{index}` has no endpoint key. `delete index` has the same shape with "Delete indices". The cases fail on the dev index until the next commit.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
`create index` listed "Create an index" eighth because the one stopword in the title switched off the only exact-title signal, and the `_create` endpoint of a document scored 6.0 for the word `create` alone. `delete index` had the same shape with "Delete indices".

Each operation now indexes its title as `api.title_fingerprint`, one token of its stemmed content words in sorted order. A query made of those words, in any order, with or without stopwords and plurals, matches it and earns `ApiLookupWeights.TitleNamed` (6.0). The lift replaces the unbounded exact-title `term` on `title.keyword`, which an index without the new field keeps through the same `dis_max`.

Measured on the dev index after a rollover: `create index` and `index create` lead at 13.13 against 11.20, `delete index` at 13.13 against 8.08, and the judged cases pass. `run a search` drops 2.1 points and keeps its order.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Four doc comments restated what the code beside them already shows. Each now keeps only the reason a reader cannot see, such as why the `match` takes no analyzer.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@reakaleek
reakaleek requested a review from a team as a code owner November 17, 2026 18:53
@reakaleek reakaleek added the bug label Nov 17, 2026
@reakaleek
reakaleek requested a review from Mpdreamz November 17, 2026 18:53
Comment on lines +30 to +40
// One token per text: its stemmed content words, sorted and joined. "Create an index", "create index" and
// "index create" all become "create index", so a query matches a title that has the same words in any order.
.Analyzer(
SharedMappingConfig.TitleFingerprintAnalyzer,
a => a
.Custom()
.Tokenizer("standard")
.Filters("lowercase", "english_stop", "title_fingerprint_stem_filter", "kstem", "fingerprint")
)
// kstem keeps "indices" apart from "index", which would leave "Delete indices" unreachable for "delete index".
.TokenFilter("title_fingerprint_stem_filter", tf => tf.StemmerOverride().Rules("indices => index"))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Severity: P3 (Low)

No CI test covers title_fingerprint_analyzer or title_fingerprint_stem_filter. The fix depends on the exact filter chain: english_stop must drop "an", the indices => index override must run before kstem, and fingerprint must come last. Only the integration relevance cases exercise this, and the PR notes those don't run in CI. If someone reorders the filters or drops the override, delete index or create index would regress without anything failing. Please add a case to the existing tests/Elastic.SiteSearch.Tests/SharedAnalysisFactoryTests.cs that asserts the analyzer's filter order and the override rule.

Generated by Libra. Specialist: libra-complexity. React with 👍 or 👎 to give feedback on this comment.

@github-actions

Copy link
Copy Markdown
Contributor

@reakaleek
reakaleek merged commit 8c6d3cb into main Nov 17, 2026
50 checks passed
@reakaleek
reakaleek deleted the fix-create-index-api-sear-c77679e8 branch November 17, 2026 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant