Searching a Million-Product Catalog: Elasticsearch, Reranking and the Woes of Turkish

On Monday morning our product manager dropped two screenshots into Slack. In the first, "TIRAŞ MAKİNESİ" (Turkish for "shaver," in capitals) had been typed into the search box, returning 4,700 results. In the second, on the same phone, "tıraş makinesi" had been typed in lowercase: 11,200 results, and a completely different first page. Underneath was a single sentence: "Which one is right?" Neither was. That week we buried ourselves in the search logs of our 14-million-product catalog and found that our zero-result rate was 11%: eleven out of every hundred searches ended on an empty page. On a platform where more than half of all traffic starts with search, that's the same as sending the people who walk in the door away empty-handed.

Capital I, Lowercase ı and a Unicode Classic

The first finding was the wall everyone who works with Turkish eventually runs into: the letter I. Unicode's default lowercase conversion turns I into i; in Turkish, however, the lowercase of I is ı (dotless i), and the lowercase of İ (dotted capital I) is i. Some of our indexes ran with the standard lowercase filter, while a normalization layer on the query side ran in Java with toLowerCase(Locale.forLanguageTag("tr")). So "TIRAŞ" became "tiraş" in the index but "tıraş" in the query, and the two could never meet. The fix looks like a single line: the turkish_lowercase token filter everywhere. But once "everywhere" spread across six different microservices, three index templates and a mobile autocomplete service, it turned into a two-week cleanup operation. The rule that came out of this case now hangs on our wall: normalization lives in one place, in one analyzer chain, no matter who sends the query from where.

Because the index lowercased with the standard filter and the query with the Turkish locale, the word TIRAŞ turned into different forms on each side.
The rule: normalization lives in a single analyzer chain.

The Customer Without Turkish Characters on Their Keyboard

The logs revealed a second truth: 38% of searches contained no Turkish characters. People were typing "kulaklik," "utu" and "camasir makinesi" instead of "kulaklık" (headphones), "ütü" (iron) and "çamaşır makinesi" (washing machine). That makes asciifolding essential, but in its pure form it's dangerous: if "sık" (dense, frequent) and "şık" (chic) fall into the same token, it's a disaster in the apparel category. We index both with preserve_original and give a higher score to matches on the original form; someone searching for "şık elbise" (chic dress) sees chic dresses, and someone who types "sik elbise" (yes, the logs are merciless; stripped of its diacritics, the word lands on an unfortunate homograph) still sees dresses. Our field strategy follows from this and has three layers: an exact field, a folded field and a stemmed field; all are produced from the same source as multi-fields, and the query is spread across all three with different boosts.

Three multi-fields are produced from the same source: exact, folded and stemmed; the query is spread across all three with different boosts.
38 percent of searches contained no Turkish characters.

The Stemmer That Digs Too Deep into the Roots

The third woe was stemming. Elasticsearch's Turkish snowball stemmer sometimes gets overly enthusiastic with our agglutinative, suffix-heavy language: in our catalog, searches for "sandalye" (chair) were polluted with results containing "sandal," and we saw embarrassing result pages where "kazak" (sweater) met products with "kaz" (goose) figures. Conversely, when we avoided aggressiveness and turned stemming off entirely, a search for "çocuk odası" (kids' room) missed products titled "çocuk odaları" (kids' rooms). We struck the balance with two moves: we pulled the stemmed field's boost well below the exact field's, and we built a hand-maintained keyword_marker + synonym list for the 2,000 most-searched terms. Synonyms are more critical in Turkish e-commerce than people think: "cep telefonu" (cell phone), "akıllı telefon" (smartphone) and "smartphone" are the same intent; so are "bebek arabası" and "puset" (both meaning stroller). This list is fed not by the search team but by the category managers; new candidates come out of the zero-result report every month. The synonym list has a trap all its own: as the list grows, nobody remembers what was added and why. Every line must include the person who added it, the date and a sample query, and every six months click data is used to audit whether each mapping still pulls its weight.

Fuzziness was a separate trap. AUTO fuzziness changes intent on short Turkish words: "kazak" (sweater) becomes "kaçak" (contraband) at an edit distance of one, and "koli" (parcel) becomes "kolye" (necklace). We enable fuzzy matching only for tokens longer than four letters, with a single edit distance and a heavily cut score; we pin a two-letter prefix so that at least the start of the word preserves the intent.

Autocomplete is a separate file altogether. The suggestion box draws far higher volume than full search; for us, up to 9 thousand suggest requests per second are generated after every three characters typed into the search box. Here we use a separate edge n-gram index, and the same Turkish woes resurface: a user typing "cam" may mean "camaşır" (a misspelling of "çamaşır," laundry), "cam bardak" (glass tumbler) or "çamaşır makinesi" (washing machine). We rank suggestions by real search frequency over the last 30 days and merge the folded and original forms under the same suggestion; otherwise the list shows two lines, "çamaşır" and "camasir," and leaves users alone with their own keyboards.

The Second Layer of Scoring

All of this solves the "find the right products" problem; "rank them right" is a different animal. For the query "iphone kılıf" (iPhone case), BM25 insisted on promoting an irrelevant product that had "kılıf" twice in its title. So we built a reranking layer: Elasticsearch fetches the top 300 candidates, and a separate service reranks them with a LambdaMART-based learning-to-rank model. The signals feeding the model include, alongside the text score, click and add-to-cart rates over the last 30 days, seller rating, stock status, price competitiveness and delivery speed. The training data comes entirely from our own click logs; without correcting for position bias, the model learned in its first run to "put what's already on top on top," and we fixed that with inverse propensity weights. We also tried cross-encoder-based semantic reranking; it gave a nice lift in nDCG but pushed p95 latency out of our 120-millisecond budget, into the 340s. For now, only queries that fall into zero results are rescued with embedding-based neighbor search; even that alone cut the empty-result rate by two points.

Changing an Analyzer Is Changing an Engine Mid-Flight

I shouldn't skip the operational side of all these changes, because an analyzer change can't be applied to an existing index; it requires a full reindex, and reindexing 14 million products takes us about 6 hours. We solve this with an alias architecture: the application never talks to a physical index name; it talks to the "products_read" and "products_write" aliases. The index with the new analyzer is filled from scratch in the background, live updates are double-written to both indexes in the meantime, comparison tests run against the new index, and the switch happens with a single atomic alias swap. If something goes wrong, rolling back is just as fast. We first compare every analyzer candidate token by token with the _analyze API against a fixture of the 10 thousand most frequent queries; after the "TIRAŞ" incident, Turkish character variations were deliberately added to this fixture, and it runs automatically in CI on every template change.

The index with the new analyzer is filled in the background, and after double writes and tests the alias is switched in a single move.
The application never talks to a physical index name.

We measure quality with a harness, not by gut feeling. There's an evaluation set of 1,500 queries; for each query we keep ideal results scored by the category managers, and every ranking change is first measured against this set with nDCG. Candidates that win offline compete live via interleaving: the results of two rankings are blended on the same page, and we look at which side the user clicks flow toward. Interleaving produces significant results with a tenth of the traffic of a classic A/B test; in a system as constantly tinkered with as search, that speed is as valuable as the experiment capacity itself.

What the Numbers Say

Here's the balance sheet of this six-month operation: the zero-result rate fell from 11% to 3.8%, add-to-cart after search rose by 9.4%, and the exit rate from the "no results found" screen was cut in half. At peak hour we serve 3,200 searches per second at a p95 of 118 milliseconds. But the metric I'm proudest of is more modest: how often our product manager sends screenshots. Search isn't a project you can call finished; every new category, every new piece of jargon, every season brings its own broken queries. If you're building Turkish search, or you've run into something like the "TIRAŞ" incident in your existing setup, the contact page is open; let's pick apart your analyzer chain together.

Cover photo: ccipeggy / Pixabay