Every Open Banking, budgeting and lending product runs into the same problem. The bank tells you a customer paid AMZN Mktp DE*2K4LM8HT5, and your product needs to say Amazon, online retail. Categorisation, contract detection, affordability checks and fraud rules all depend on getting that step right.
Elasticsearch handles this well, but not with a single query. This is the setup we use: normalise first, look up exact matches during ingest, and send the rest to a fuzzy search and a review queue.
Why descriptors are hard
The same merchant shows up in many forms:
| Raw descriptor | What it means |
|---|---|
AMZN Mktp DE*2K4LM8HT5 |
Amazon Marketplace, with an order reference |
AMAZON PAYMENTS EUROPE S.C.A. |
The same, through another acquirer |
PAYPAL *SPOTIFY 35314369001 |
Spotify, paid through PayPal |
SumUp *Cafe Mueller Kassel |
A small café, through a card terminal provider |
LIDL SAGT DANKE 1234 |
Lidl, with a store number and a slogan |
The noise has a pattern: payment processor prefixes, order references, store numbers, city names, dates and card fragments. A plain match query on the raw text matches on that noise instead of the merchant.
Step 1: normalise in an ingest pipeline
Clean every descriptor into a stable key before anything else. An ingest pipeline does this at index time, so queries and lookups only ever see the clean form.
PUT _ingest/pipeline/transactions
{
"processors": [
{ "lowercase": { "field": "descriptor", "target_field": "descriptor_key" } },
{ "gsub": { "field": "descriptor_key", "pattern": "^(paypal|sumup|sq|izettle|klarna)\\s*\\*", "replacement": "" } },
{ "gsub": { "field": "descriptor_key", "pattern": "\\*.*$", "replacement": "" } },
{ "gsub": { "field": "descriptor_key", "pattern": "[^\\p{L} ]", "replacement": " " } },
{ "gsub": { "field": "descriptor_key", "pattern": "\\b(sagt danke|gmbh|s c a|sarl|ltd)\\b", "replacement": " " } },
{ "gsub": { "field": "descriptor_key", "pattern": "\\s+", "replacement": " " } },
{ "trim": { "field": "descriptor_key" } }
]
}
AMZN Mktp DE*2K4LM8HT5 becomes amzn mktp de. PAYPAL *SPOTIFY 35314369001 becomes spotify. Keep the rules in version control and test them against a sample of real descriptors: a rule that is too aggressive merges merchants that should stay apart.
Step 2: exact lookup with an enrich policy
Keep a merchant dictionary as its own index: one document per known descriptor key, pointing to the canonical merchant, category and logo.
PUT merchants/_doc/amzn-mktp-de
{ "descriptor_key": "amzn mktp de", "merchant": "Amazon", "category": "shopping.online_retail", "logo": "amazon" }
An enrich policy turns that index into a fast lookup table the pipeline can use:
PUT _enrich/policy/merchants
{
"match": {
"indices": "merchants",
"match_field": "descriptor_key",
"enrich_fields": ["merchant", "category", "logo"]
}
}
POST _enrich/policy/merchants/_execute
Then add the enrich step at the end of the pipeline:
{ "enrich": { "policy_name": "merchants", "field": "descriptor_key", "target_field": "merchant_info", "ignore_missing": true } }
Two things to know. The enrich index is a snapshot, so run _execute again after the dictionary changes (a scheduled job works). And enrich match is exact: it only helps once the key is in the dictionary. That is fine, because a small set of merchants covers most of the volume. Supermarkets, streaming services, telecoms and the big online shops are usually well over half of all transactions.
Step 3: fuzzy search for everything else
Transactions that leave the pipeline without merchant_info go to a second step. Search the merchant dictionary with the cleaned key, allowing typos and partial matches. Here descriptor_key.ngram is a sub-field analysed into three-letter fragments:
GET merchants/_search
{
"size": 3,
"query": {
"bool": {
"should": [
{ "match": { "merchant": { "query": "cafe mueller kassel", "fuzziness": "AUTO", "boost": 2 } } },
{ "match": { "descriptor_key.ngram": { "query": "cafe mueller kassel" } } }
]
}
}
}
Above a score you have calibrated on labelled data, accept the match and add the new descriptor key to the dictionary. Below it, send the transaction to a review queue. Every reviewed answer becomes a new dictionary entry, so the share of unknown descriptors drops week by week.
Step 4: contracts and recurring payments
Once the merchant is known, recurring payments are an aggregation problem: the same merchant, a similar amount, at a regular interval. A transform that groups by account and merchant, and stores the count, the median amount and the median gap in days, gives you a contracts index that is cheap to query. Rent, insurance, phone and streaming contracts appear without any rules per merchant.
What to measure
- Match rate: share of transactions with a merchant, by count and by amount.
- Precision: from a labelled sample, the share of matches that are right. A wrong merchant is worse than none.
- Unknown descriptors per week: should go down as the dictionary grows.
- Ingest latency: enrich lookups are fast, but check it under peak load.
Working with regulated data
You do not need production data to build this. Descriptor rules and matching can be developed on anonymised samples, with account numbers and names removed, and then run inside your own environment. This is how we work with banks and fintechs; see Elasticsearch for fintech. For screening people rather than merchants, read fuzzy name matching for AML screening.
