Backend Engineer: Tuning Elasticsearch for Complex Electronic Part Numbers, OCR Typos & Delimiter-Insensitive Search
Searching technical catalogs for semiconductor Manufacturer Part Numbers (MPNs), automotive VINs, or medical device SKUs is fundamentally different from natural-language prose search. When an engineer searches for "STM32F407VGT6" or mistypes "STM32-F407VG" (substituting `0` vs `O`, `1` vs `I`, or adding/omitting hyphens and slashes), standard Levenshtein edit distance (`fuzziness: "AUTO"`) across the whole token can accidentally match a completely different voltage or pin-count variant (`"STM32F405VGT6"`). As a Backend Engineer, I design precision-ranked alphanumeric part number analyzers in Elasticsearch and OpenSearch.
1. Combining `word_delimiter_graph` with Character-Filter Delimiter Stripping
To support queries with or without hyphens, dots, and slashes (`"TPS7A4700-RGWT"` vs `"TPS7A4700RGWT"` vs `"TPS7A4700"`), we index three parallel sub-fields on every `mpn` attribute: an exact normalized keyword, a delimiter-stripped continuous token, and a `word_delimiter_graph` sub-token index with `preserve_original: true`:
{
"settings": {
"analysis": {
"char_filter": {
"strip_delimiters": {
"type": "pattern_replace",
"pattern": "[\-\./_\s]+",
"replacement": ""
}
},
"filter": {
"mpn_word_delimiter": {
"type": "word_delimiter_graph",
"generate_word_parts": true,
"generate_number_parts": true,
"catenate_all": true,
"split_on_case_change": false,
"split_on_numerics": false,
"preserve_original": true
}
},
"analyzer": {
"mpn_compact_analyzer": {
"type": "custom",
"char_filter": ["strip_delimiters"],
"tokenizer": "keyword",
"filter": ["lowercase"]
},
"mpn_segmented_analyzer": {
"type": "custom",
"tokenizer": "whitespace",
"filter": ["mpn_word_delimiter", "lowercase"]
}
}
}
}
}
2. DisMax Multi-Tier Scoring Hierarchy for Zero False-Positive Substitutions
At query time, a `dis_max` query scores exact delimiter-stripped hits (`boost: 20.0`) far above prefix matches (`boost: 5.0`), segmented sub-part matches (`boost: 2.0`), and bounded `fuzziness: 1` (`prefix_length: 4`) fallback matches—powering our real-time BOM upload & quoting engine and sub-10ms Edge N-Gram Elasticsearch lookup pipeline.
Need a Backend Engineer to build high-precision SKU and part-number search in Elasticsearch or PostgreSQL? Book a 1-Day Engineering Sprint.