Skip to content

Rank an API operation by its route when the request line has another method - #4910

Merged
reakaleek merged 2 commits into
mainfrom
fix-api-search-get-route-f670ee82
Nov 17, 2026
Merged

reakaleek merged 2 commits into
mainfrom
fix-api-search-get-route-f670ee82

Conversation

@reakaleek

@reakaleek reakaleek commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

API search now ranks POST /{index}/_search first for GET /_search, where it used to list "Get the search shards" first and "Run a search" fourth.

Affects: Search, API reference

Prompt summary: Fix API search for a pasted request line whose method differs from the operation's canonical one, found while verifying newsletter examples. The route must decide the ranking, and a mismatched method may cost a little but never drop the operation below operations that only share a word with its path.

Why

The whole-title lift reads the raw query, so GET /_search asks for a title that holds get and search*. Every "Get … search …" title earns that lift (3.0) and "Run a search" does not. The method is not required or demoted: it only adds a 0.5 lift, so the mismatch was never the cause.

What

The method names the verb, not a title word

Tokenize already folds a method typed before a path into the path word. The title lifts (title_all, title_named, starts-with and the landing-page guards) now read the same query without that method, through TitleText. A method that does not sit before a path, as in get cluster settings, stays a title word, and every query without a method before a path builds the same text as before. The method still lifts operations that use it by ApiLookupWeights.Method.

Judged cases

GET /_search is a new judged case, in its own commit ahead of the fix. The controls POST /_search, /_search, /_search knn, GET /_cluster/health and GET /_search_shards pass before and after. A unit test pins the title text the lifts receive.

The docs-wide search is unchanged: only ApiLookupQueryBuilder changed, and SearchQueryBuilder did not.

Verify

Measured through the real gateway on the dev index, top three of ApiSearchRelevanceReport before and after:

Query Before After
GET /_search search shards 9.13, searchable snapshot stats 9.11, cache stats 9.07 search 10.20 (stack and Serverless), scroll 9.70
POST /_search, /_search search first same
GET /_cluster/health cluster health 10.65 same

Across the 82 reported queries the top three changed only for GET /_search. Scores moved without reordering for POST /_count (7.20 to 10.20, the title now matches count) and HEAD / (12.86 to 9.86, the lone / is no title word; its margin over info is still 2.66).

dotnet test --project tests/Elastic.Documentation.Api.Tests
# needs the dev index
ENVIRONMENT=dev DOCS_BUILD_TYPE=assembler dotnet test --project tests-integration/Search.IntegrationTests/ --treenode-filter "/*/*/SearchRelevanceTests/ApiSearch*"

Regression checks, all on the dev index:

  • Same query text elsewhere. 98 queries without a method before a path serialize to byte-identical DSL on the old and new builder. The 12 that differ are all request lines.
  • Request-line holdout. 30 extra request lines (partial paths, lowercase methods, DELETE, PUT, PATCH, Kibana routes) diffed before and after. Most only gained or lost a flat 3.0 with the same order. GET /_sear and GET /{index}/_search now lead with search. Four third places changed to operations that name the typed route: GET /_security/user, GET /_mapping, GET /_ml/anomaly_detectors and POST /_reindex. Before, a title that starts with Get held that place.
  • Local service. GET /_search, POST /_search, /_search and GET /_cluster/health on a Debug build return the same order as the gateway report.

The integration cases are not run in CI. ApiSearchPlainWordDoesNotCoverTheRoutesUnderItsOwnName also fails on main.

Out of scope: GET /_search ranks the POST operation 0.5 below POST /_search, which is the intended cost of the mismatch.

🤖 Generated with Claude Code

reakaleek and others added 2 commits November 17, 2026 20:29
…ethod

`GET /_search` lists "Get the search shards" first and "Run a search" fourth, while `POST /_search` and `/_search` list "Run a search" first. The case fails on the dev index until the next commit. The controls `POST /_search`, `/_search`, `/_search knn`, `GET /_cluster/health` and `GET /_search_shards` pass today and pin the other side.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…method

`GET /_search` listed "Get the search shards" first because the whole-title lift read the raw query, so `get` and `search*` had to be title words. "Run a search" lost that 3.0 and fell to fourth. A method typed before a path now names only the verb: the title lifts read the query without it, and the method still lifts operations that use it by 0.5.

Measured on the dev index, `GET /_search` lists "Run a search" first at 10.20, then the scrolling search at 9.70. Queries without a method before a path build the same text as before.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@reakaleek
reakaleek requested a review from a team as a code owner November 17, 2026 19:32
@reakaleek
reakaleek requested a review from technige November 17, 2026 19:32
@reakaleek reakaleek added the bug label Nov 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

@reakaleek
reakaleek merged commit 647d3ca into main Nov 17, 2026
50 checks passed
@reakaleek
reakaleek deleted the fix-api-search-get-route-f670ee82 branch November 17, 2026 19:48
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.

2 participants