sdm插件生态全解析:从网络配置到Docker部署的10大实用插件
2026/7/28 6:12:20
Elasticsearch 对结构化数据(Structured)与非结构化数据(Unstructured / 全文)的处理机制截然不同,其核心在于字段类型(Mapping)与底层存储结构的差异。正确区分并设计两类数据,是构建高性能、高可用搜索系统的基石。
| 特性 | 结构化数据 | 非结构化数据(全文) |
|---|---|---|
| 典型字段 | keyword,integer,date,boolean | text |
| 存储结构 | Doc Values(列式存储) | 倒排索引(Inverted Index) |
| 查询用途 | 精确匹配、范围查询、聚合、排序 | 全文搜索、相关性评分 |
| 分析器 | 无(原始值存储) | 有(分词、转小写等) |
| 内存使用 | 低(压缩列存) | 中(倒排索引) |
💡关键认知:
结构化 = 精确值操作,非结构化 = 语义匹配
keyword/ 数值类型{"product_id":{"type":"long"},"brand":{"type":"keyword"},"price":{"type":"float"},"in_stock":{"type":"boolean"},"created_at":{"type":"date"}}term查询(精确匹配)range查询(价格/时间范围)terms聚合)sort)text+ 分析器{"description":{"type":"text","analyzer":"ik_max_word","search_analyzer":"ik_smart"}}match查询(分词后匹配)highlight){"product_name":{"type":"text","analyzer":"ik_max_word","fields":{"keyword":{"type":"keyword"}}}}product_name:全文搜索(“手机” → 匹配“智能手机”)product_name.keyword:精确过滤/聚合(品牌 = “Apple”)PUT/products{"mappings":{"properties":{"id":{"type":"long"},"name":{"type":"text","analyzer":"ik_max_word","fields":{"keyword":{"type":"keyword"}}},"description":{"type":"text","analyzer":"ik_max_word"},"brand":{"type":"keyword"},"price":{"type":"float"},"in_stock":{"type":"boolean"},"created_at":{"type":"date"}}}}POST/products/_search{"query":{"bool":{"must":[{"match":{"name":"iPhone 手机"}}],"filter":[{"term":{"brand":"Apple"}},{"range":{"price":{"gte":5000,"lte":10000}}},{"term":{"in_stock":true}}]}},"aggs":{"brands":{"terms":{"field":"brand","size":10}},"price_ranges":{"range":{"field":"price","ranges":[{"to":5000},{"from":5000,"to":10000},{"from":10000}]}}},"sort":[{"price":"desc"}],"highlight":{"fields":{"name":{},"description":{}}}}useElasticsearch\ClientBuilder;classProductService{publicfunctionsearch($keyword,$filters){$client=ClientBuilder::create()->build();$query=['bool'=>['must'=>[['match'=>['name'=>$keyword]]],'filter'=>[]]];// 结构化过滤if(!empty($filters['brand'])){$query['bool']['filter'][]=['term'=>['brand'=>$filters['brand']]];}if(!empty($filters['min_price'])){$query['bool']['filter'][]=['range'=>['price'=>['gte'=>$filters['min_price']]]];}$params=['index'=>'products','body'=>['query'=>$query,'aggs'=>['brands'=>['terms'=>['field'=>'brand.keyword']]],'sort'=>['price'=>'desc'],'highlight'=>['fields'=>['name'=>new\stdClass]]]];return$client->search($params);}}| 陷阱 | 破局方案 |
|---|---|
| 对 text 字段聚合 | 必须使用.keyword子字段 |
| 忽略高基数 keyword | ID 类字段用long,非keyword |
| 全文搜索用 term | 全文用match,精确用term |
| 未配中文分词器 | text字段必须指定ik_max_word |
**“结构化与非结构化,
不是数据之分,而是用途之别——
- 当你用 keyword,
你在定义精确边界;- 当你用 text,
你在释放语义力量;- 当你设计 multi-field,
你在融合二者之长。真正的搜索系统,
始于对数据的敬畏,
成于对用途的洞察。”
从今天起:
.keywordmatch,过滤用termlong/float,非keyword因为最好的搜索体验,
不是模糊匹配,
而是精准融合结构与语义。