options名称和取值统计.md
4.34 KB
prompt
参考 @docs/常用查询 - ES.md 帮我查询 tenant_Id=163的@search_products.json (1314-1332) 这些字段的统计分布,也就是这里每个字段的所有的值及其对应的文档数
已按 docs/常用查询 - ES.md 的写法,在索引 search_products_tenant_163 上做了 terms 聚合(租户已按索引拆分,用 match_all 即可,等价于只查 tenant 163)。集群在本机 localhost:9200 上执行成功。
结果概要
- 总文档数:8977
- 六个字段的
sum_other_doc_count均为 0,在size: 20000下没有截断,即:当前数据里每个字段的取值都已全部列出。 __missing__:来自聚合里的"missing": "__missing__",表示该字段缺失或为空的文档数(便于和「有值」一起看)。option1_values/option2_values多为多值数组:同一篇文档可落入多个桶,因此 各桶doc_count之和会大于 8977(这是 ESterms的正常语义,表示「含该取值的文档数」,不是互斥分区)。option1_name/option2_name/option3_name及option3_values的桶计数之和与文档关系更接近单值/稀疏(见下方校验)。
option1_name(13 个取值)
| 值 | 文档数 |
|---|---|
| missing | 4538 |
| Size | 2916 |
| Color | 1174 |
| 颜色 | 244 |
| COLOR | 56 |
| color | 16 |
| Colour | 15 |
| Variant | 9 |
| Style | 3 |
| Colors | 2 |
| Scent | 2 |
| Cup Size | 1 |
| Pattern Name | 1 |
option2_name(13 个取值)
| 值 | 文档数 |
|---|---|
| missing | 4666 |
| Color | 2879 |
| Size | 1134 |
| 尺码 | 244 |
| SIZE | 17 |
| size | 16 |
| Style | 12 |
| Cup Size | 4 |
| Item Package Quantity | 1 |
| Number of Items | 1 |
| Ring Size | 1 |
| Scent | 1 |
| Team Name | 1 |
option3_name(11 个取值)
| 值 | 文档数 |
|---|---|
| missing | 8831 |
| Fit Type | 52 |
| Special Size | 31 |
| Number of Items | 17 |
| Special Size Type | 16 |
| Team Name | 15 |
| Material Type | 8 |
| Style | 4 |
| Configuration | 1 |
| Hand Orientation | 1 |
| Pattern Name | 1 |
option1_values / option2_values
- 桶数量:
option1_values3463,option2_values3605(完整列表过长,不宜贴在对话里)。 - 文档中出现最多的取值(前 10)
- option1_values:
__missing__4538,其后如 Medium 749、Black 653、Large 635、8/9/White/10/7/Small… - option2_values:
__missing__4666,其后如 L 1161、M 1158、S 1064、XL 1036、Black 876…
- option1_values:
option3_values(94 个桶,已全部枚举)
除 __missing__ 8831 外,另有 93 个具体取值;上文 Markdown 表里已列全(从 Standard 到 standard 等)。
可复用的查询(与文档一致)
curl -sS -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' \
-H 'Content-Type: application/json' -d '{
"query": { "match_all": {} },
"size": 0,
"track_total_hits": true,
"aggs": {
"option1_name_dist": {
"terms": { "field": "option1_name", "size": 20000, "order": { "_count": "desc" }, "missing": "__missing__" }
},
"option2_name_dist": {
"terms": { "field": "option2_name", "size": 20000, "order": { "_count": "desc" }, "missing": "__missing__" }
},
"option3_name_dist": {
"terms": { "field": "option3_name", "size": 20000, "order": { "_count": "desc" }, "missing": "__missing__" }
},
"option1_values_dist": {
"terms": { "field": "option1_values", "size": 20000, "order": { "_count": "desc" }, "missing": "__missing__" }
},
"option2_values_dist": {
"terms": { "field": "option2_values", "size": 20000, "order": { "_count": "desc" }, "missing": "__missing__" }
},
"option3_values_dist": {
"terms": { "field": "option3_values", "size": 20000, "order": { "_count": "desc" }, "missing": "__missing__" }
}
}
}'
若某租户取值超过 2 万,需把 size 再加大或用 composite 分页扫完全部桶。
完整 JSON(含 3463 + 3605 条 value 分布)
已整理为:/tmp/tenant163_option_fields_distribution.json(约 620KB),结构为按字段分组的 values: [{ "value", "doc_count" }, ...],便于你用脚本或表格工具打开。
如需去掉 __missing__ 桶,从请求里删掉各聚合中的 "missing": "__missing__" 即可。