Composer and Author Name Variants in Elasticsearch

Tchaikovsky, Tschaikowsky and Chaikovsky. Dvořák and Dvorak. How to make catalogue search find every spelling of a name with folding, an alias field and an updateable synonym list.

Music and book catalogues are full of names that are spelled several ways. A German customer types Tschaikowsky, an American types Tchaikovsky, and a library record says Čajkovskij. If your search only knows one of them, two out of three customers find nothing.

There are three kinds of name variants, and each needs a different fix.

1. Accents and special letters

Dvořák and Dvorak, Fauré and Faure, Händel and Handel. Customers rarely type accents.

Fix: fold accents away at index and search time with asciifolding. For German names, add german_normalization, which also turns ae, oe and ue into a, o and u, so Haendel matches too.

"analyzer": {
  "person_name": {
    "tokenizer": "standard",
    "filter": ["lowercase", "german_normalization", "asciifolding"]
  }
}

Keep the original spelling in the source document for display. Only the index uses the folded form.

2. Transliterations

Tchaikovsky, Tschaikowsky, Chaikovsky, Ciajkovskij. Rachmaninoff and Rachmaninov. Mussorgsky and Musorgskij. These come from writing a Russian name in different languages' alphabets, and they are too far apart for typo tolerance to bridge.

Fix: an alias field. Give every composer or author record a list of known variants, and index it with the product:

{
  "title": "Nutcracker Suite, Op. 71a",
  "composer": "Pyotr Ilyich Tchaikovsky",
  "composer_aliases": ["Tschaikowsky", "Chaikovsky", "Ciajkovskij", "Tchaikowsky", "Čajkovskij"]
}

Search composer and composer_aliases together, with the main name weighted higher:

{ "multi_match": { "query": "tschaikowsky", "fields": ["composer^3", "composer_aliases^2", "title"] } }

You do not have to collect the variants by hand. Library authority files such as VIAF and the Library of Congress name authorities, and open databases such as MusicBrainz, list variant spellings for most composers and many authors. Import them once, then add what your own search logs show.

3. Customer shorthand

PDQ Bach, JS Bach, Bach BWV 248, Lloyd Webber without Andrew. And the ambiguous ones: "Bach" means Johann Sebastian to most customers, but your catalogue also has C.P.E. Bach.

Fix: a synonym list that your staff can edit, applied at search time:

PUT _synonyms/names
{
  "synonyms_set": [
    { "id": "jsbach", "synonyms": "js bach, j s bach, johann sebastian bach" },
    { "id": "alw", "synonyms": "lloyd webber, andrew lloyd webber" },
    { "id": "rach", "synonyms": "rachmaninoff, rachmaninov, rakhmaninov" }
  ]
}
"filter": {
  "name_synonyms": { "type": "synonym_graph", "synonyms_set": "names", "updateable": true }
},
"analyzer": {
  "person_name_search": {
    "tokenizer": "standard",
    "filter": ["lowercase", "german_normalization", "asciifolding", "name_synonyms"]
  }
}

Use person_name_search as the search_analyzer on the name fields. Because the synonyms are applied at search time and marked updateable, a change in the list takes effect immediately, without reindexing. Synonym sets need Elasticsearch 8.10 or later; on older versions, use a synonyms file and reload the search analyzers.

For ambiguous names, use ranking instead of synonyms: boost the composer customers mean most often, based on clicks and sales, and let the others follow.

When to use phonetic matching

Phonetic filters (Double Metaphone, Beider-Morse) match names that sound alike. They are useful as a last fallback for rare names, but they also match names that only roughly sound alike, so results get noisy. In catalogues we use them on a separate sub-field with a low weight, never as the main match.

Work numbers belong here too

Composers' works are often found by catalogue number: BWV 248, K. 525, Op. 71a, D. 944. Index them as their own field, normalised the same way as product codes (see searching ISBNs and catalogue numbers), so bwv248, BWV 248 and bwv-248 all match.

Test with your own search logs

Pull every search from the last three months that contains a name, group by composer or author, and check that each variant finds the right person's works. The zero-result list will show you which variants are still missing.

We tune name search for music, book and educational publishers on the Elasticsearch they already run. See catalogue search for publishers and why your catalogue search returns no results.

Talk to an Elasticsearch expert

We reply within one business day. Your details are used only to answer you.