8cff1628
tangwang
tenant2 1w测试数据 mo...
|
1
|
|
577ec972
tangwang
返回给前端的字段、格式适配。主要包...
|
2
|
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
3
|
## Elasticsearch 排查流程
|
1681a135
tangwang
image_embeddin si...
|
4
|
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
### 1. 集群健康状态
```bash
# 集群整体健康(green / yellow / red)
curl -s -u 'saas:4hOaLaf41y2VuI8y' 'http://127.0.0.1:9200/_cluster/health?pretty'
```
### 2. 索引概览
```bash
# 查看所有租户索引状态与体积
curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/_cat/indices/search_products_tenant_*?v'
# 或查看全部索引
curl -s -u 'saas:4hOaLaf41y2VuI8y' 'http://127.0.0.1:9200/_cat/indices?v'
```
### 3. 分片分布
```bash
# 查看分片在各节点的分布情况
curl -s -u 'saas:4hOaLaf41y2VuI8y' 'http://127.0.0.1:9200/_cat/shards?v'
```
### 4. 分配诊断(如有异常)
```bash
# 当 health 非 green 或 shards 状态异常时,定位具体原因
curl -s -u 'saas:4hOaLaf41y2VuI8y' -X POST 'http://127.0.0.1:9200/_cluster/allocation/explain?pretty' \
-H 'Content-Type: application/json' \
-d '{"index":"search_products_tenant_163","shard":0,"primary":true}'
```
> 典型结论示例:`disk_threshold` — 磁盘超过高水位,新分片禁止分配。
### 5. 系统层检查
```bash
# 服务状态
sudo systemctl status elasticsearch
# 磁盘空间
df -h
# ES 数据目录占用
du -sh /var/lib/elasticsearch/
```
### 6. 配置与日志
```bash
# 配置文件
cat /etc/elasticsearch/elasticsearch.yml
# 实时日志
journalctl -u elasticsearch -f
```
|
1fdab52d
tangwang
This change adjus...
|
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
### 7. 修改索引级设置(如 BM25 `similarity.default`)
`mappings/search_products.json` 里的 `settings.similarity` 只在**创建新索引**时生效;**已有索引**需先关闭索引,再 `PUT _settings`,最后重新打开。
**适用场景**:调整默认 BM25 的 `b`、`k1`(例如与仓库映射对齐:`b: 0.1`、`k1: 0.3`)。
```bash
# 按需替换:索引名、账号密码、ES 地址
INDEX="search_products_tenant_163"
AUTH='saas:4hOaLaf41y2VuI8y'
ES="http://localhost:9200"
# 1) 关闭索引(写入类请求会失败,注意维护窗口)
curl -s -u "$AUTH" -X POST "$ES/${INDEX}/_close"
# 2) 更新设置(仅示例:与 mappings 中 default 一致时可照抄)
curl -s -u "$AUTH" -X PUT "$ES/${INDEX}/_settings" \
-H 'Content-Type: application/json' \
-d '{
"index": {
"similarity": {
"default": {
"type": "BM25",
"b": 0.1,
"k1": 0.3
}
}
}
}'
# 3) 重新打开索引
curl -s -u "$AUTH" -X POST "$ES/${INDEX}/_open"
```
**检查是否生效**:
```bash
curl -s -u "$AUTH" -X GET "$ES/${INDEX}/_settings?filter_path=**.similarity&pretty"
```
期望在响应中看到 `similarity.default` 的 `type`、`b`、`k1`(API 可能将数值以字符串形式返回,属正常)。
**多租户批量**:先列出索引,再对每个 `search_products_tenant_*` 重复上述 close → settings → open。
```bash
curl -s -u "$AUTH" -X GET "$ES/_cat/indices/search_products_tenant_*?h=index&v"
```
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
---
### 快速排查路径
```
_cluster/health → 确认集群状态(green/yellow/red)
↓
_cat/indices → 检查索引体积与状态
↓
_cat/shards → 查看分片分布
↓
_cluster/allocation/explain → 定位分配问题(如需要)
↓
systemctl / df / 日志 → 系统层验证
```
---
以下是将您提供的 Elasticsearch 查询整理为 Markdown 格式的文档:
---
# Elasticsearch 查询集合
## 租户相关
> **说明**:索引已按租户拆分为 `search_products_tenant_{tenant_id}`,一般情况下不需要在查询中再按 `tenant_id` 过滤(可选保留用于排查)。
---
|
5ac64fc7
tangwang
多语言查询
|
139
140
|
### 1. 根据 tenant_id / spu_id 查询
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
141
142
143
144
|
#### 查询指定 spu_id 的商品(返回 title)
```bash
curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_170/_search?pretty' -H 'Content-Type: application/json' -d '{
|
472cca0c
tangwang
doc
|
145
|
"size": 11,
|
80f87e57
tangwang
多语言索引修改 对应的 索引创建、...
|
146
|
"_source": ["title"],
|
472cca0c
tangwang
doc
|
147
|
"query": {
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
148
149
150
151
152
|
"bool": {
"filter": [
{ "term": {"spu_id" : 206150} }
]
}
|
472cca0c
tangwang
doc
|
153
|
}
|
89638140
tangwang
重构 indexer 文档构建接口...
|
154
|
}'
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
155
|
```
|
c4263d93
tangwang
支持 sku_filter_dim...
|
156
|
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
157
158
159
160
161
162
163
|
#### 查询所有商品(返回 title)
```bash
curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_170/_search?pretty' -H 'Content-Type: application/json' -d '{
"size": 100,
"_source": ["title"],
"query": {
"match_all": {}
|
985d7fe3
tangwang
为 filters 中所有字段加上...
|
164
|
}
|
89638140
tangwang
重构 indexer 文档构建接口...
|
165
|
}'
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
166
|
```
|
985d7fe3
tangwang
为 filters 中所有字段加上...
|
167
|
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
168
169
170
171
172
173
174
175
176
177
|
#### 查询指定 spu_id 的商品(返回 title、keywords、tags)
```bash
curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_170/_search?pretty' -H 'Content-Type: application/json' -d '{
"size": 5,
"_source": ["title", "keywords", "tags"],
"query": {
"bool": {
"filter": [
{ "term": { "spu_id": "223167" } }
]
|
89638140
tangwang
重构 indexer 文档构建接口...
|
178
|
}
|
985d7fe3
tangwang
为 filters 中所有字段加上...
|
179
|
}
|
985d7fe3
tangwang
为 filters 中所有字段加上...
|
180
|
}'
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
181
|
```
|
985d7fe3
tangwang
为 filters 中所有字段加上...
|
182
|
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
#### 组合查询:匹配标题 + 过滤标签
```bash
curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_170/_search?pretty' -H 'Content-Type: application/json' -d '{
"size": 1,
"_source": ["title", "keywords", "tags"],
"query": {
"bool": {
"must": [
{
"match": {
"title.en": {
"query": "Floerns Women Gothic Graphic Ribbed Strapless Tube Top Asymmetrical Ruched Bandeau Tops"
}
}
}
],
"filter": [
{ "terms": { "tags": ["女装", "派对"] } }
]
}
}
}'
```
|
985d7fe3
tangwang
为 filters 中所有字段加上...
|
206
|
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
207
208
209
|
#### 组合查询:匹配标题 + 过滤租户(冗余示例)
```bash
curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_170/_search?pretty' -H 'Content-Type: application/json' -d '{
|
5ac64fc7
tangwang
多语言查询
|
210
|
"size": 1,
|
d7d48f52
tangwang
改动(mapping + 灌入结构)
|
211
|
"_source": ["title"],
|
5ac64fc7
tangwang
多语言查询
|
212
|
"query": {
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
213
214
215
216
217
218
219
220
221
222
223
224
225
226
|
"bool": {
"must": [
{
"match": {
"title.en": {
"query": "Floerns Women Gothic Graphic Ribbed Strapless Tube Top Asymmetrical Ruched Bandeau Tops"
}
}
}
],
"filter": [
{ "term": { "tenant_id": "170" } }
]
}
|
5ac64fc7
tangwang
多语言查询
|
227
228
|
}
}'
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
229
|
```
|
5ac64fc7
tangwang
多语言查询
|
230
|
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
231
232
233
|
---
### 2. 分析器测试
|
5ac64fc7
tangwang
多语言查询
|
234
|
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
235
236
237
238
239
|
#### 测试 index_ik 分析器
```bash
curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_170/_analyze' -H 'Content-Type: application/json' -d '{
"analyzer": "index_ik",
"text": "14寸第4代-眼珠实身冰雪公仔带手动大推车,搪胶雪宝宝"
|
5ac64fc7
tangwang
多语言查询
|
240
|
}'
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
241
|
```
|
5ac64fc7
tangwang
多语言查询
|
242
|
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
243
244
245
246
247
|
#### 测试 query_ik 分析器
```bash
curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_170/_analyze' -H 'Content-Type: application/json' -d '{
"analyzer": "query_ik",
"text": "14寸第4代-眼珠实身冰雪公仔带手动大推车,搪胶雪宝宝"
|
5ac64fc7
tangwang
多语言查询
|
248
|
}'
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
249
|
```
|
5ac64fc7
tangwang
多语言查询
|
250
|
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
|
---
### 3. 多字段搜索 + 聚合(综合分面示例)
#### 多字段匹配 + 聚合(category1、color、size、material)
```bash
curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_170/_search?pretty' -H 'Content-Type: application/json' -d '{
"size": 1,
"from": 0,
"query": {
"bool": {
"must": [
{
"multi_match": {
"_name": "base_query",
"fields": [
"title.zh^3.0",
"brief.zh^1.5",
"description.zh",
"vendor.zh^1.5",
"tags",
"category_path.zh^1.5",
"category_name_text.zh^1.5",
"option1_values^0.5"
],
"minimum_should_match": "75%",
"operator": "AND",
"query": "裙",
"tie_breaker": 0.9
}
}
|
5ac64fc7
tangwang
多语言查询
|
282
|
],
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
283
284
285
|
"filter": [
{ "match_all": {} }
]
|
5ac64fc7
tangwang
多语言查询
|
286
|
}
|
5ac64fc7
tangwang
多语言查询
|
287
|
},
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
288
289
290
291
292
293
|
"aggs": {
"category1_name_facet": {
"terms": {
"field": "category1_name",
"size": 15,
"order": { "_count": "desc" }
|
5ac64fc7
tangwang
多语言查询
|
294
|
}
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
|
},
"specifications_color_facet": {
"nested": { "path": "specifications" },
"aggs": {
"filter_by_name": {
"filter": { "term": { "specifications.name": "color" } },
"aggs": {
"value_counts": {
"terms": {
"field": "specifications.value",
"size": 20,
"order": { "_count": "desc" }
}
}
}
|
5ac64fc7
tangwang
多语言查询
|
310
|
}
|
5ac64fc7
tangwang
多语言查询
|
311
|
}
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
|
},
"specifications_size_facet": {
"nested": { "path": "specifications" },
"aggs": {
"filter_by_name": {
"filter": { "term": { "specifications.name": "size" } },
"aggs": {
"value_counts": {
"terms": {
"field": "specifications.value",
"size": 15,
"order": { "_count": "desc" }
}
}
}
|
5ac64fc7
tangwang
多语言查询
|
327
|
}
|
5ac64fc7
tangwang
多语言查询
|
328
|
}
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
|
},
"specifications_material_facet": {
"nested": { "path": "specifications" },
"aggs": {
"filter_by_name": {
"filter": { "term": { "specifications.name": "material" } },
"aggs": {
"value_counts": {
"terms": {
"field": "specifications.value",
"size": 10,
"order": { "_count": "desc" }
}
}
}
|
5ac64fc7
tangwang
多语言查询
|
344
|
}
|
5ac64fc7
tangwang
多语言查询
|
345
|
}
|
5ac64fc7
tangwang
多语言查询
|
346
|
}
|
5ac64fc7
tangwang
多语言查询
|
347
|
}
|
5ac64fc7
tangwang
多语言查询
|
348
|
}'
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
349
350
351
352
353
|
```
---
### 4. 通用查询(通用索引示例)
|
5ac64fc7
tangwang
多语言查询
|
354
|
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
355
356
|
#### 查询所有
```bash
|
89638140
tangwang
重构 indexer 文档构建接口...
|
357
|
GET /search_products_tenant_2/_search
|
5ac64fc7
tangwang
多语言查询
|
358
|
{
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
359
360
361
|
"query": {
"match_all": {}
}
|
5ac64fc7
tangwang
多语言查询
|
362
|
}
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
363
|
```
|
c4263d93
tangwang
支持 sku_filter_dim...
|
364
|
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
365
366
367
|
#### 按 spu_id 查询(通用索引)
```bash
curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products/_search?pretty' -H 'Content-Type: application/json' -d '{
|
c4263d93
tangwang
支持 sku_filter_dim...
|
368
369
|
"size": 5,
"query": {
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
370
371
372
373
374
|
"bool": {
"filter": [
{ "term": { "spu_id": "74123" } }
]
}
|
c4263d93
tangwang
支持 sku_filter_dim...
|
375
|
}
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
376
377
378
379
|
}'
```
---
|
c4263d93
tangwang
支持 sku_filter_dim...
|
380
|
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
381
|
### 5. 统计租户总文档数
|
c4263d93
tangwang
支持 sku_filter_dim...
|
382
|
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
383
|
```bash
|
484adbfe
tangwang
adapt ubuntu; con...
|
384
|
curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_170/_count?pretty' -H 'Content-Type: application/json' -d '{
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
385
386
387
|
"query": {
"match_all": {}
}
|
5ac64fc7
tangwang
多语言查询
|
388
|
}'
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
389
|
```
|
5ac64fc7
tangwang
多语言查询
|
390
|
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
391
|
---
|
5ac64fc7
tangwang
多语言查询
|
392
|
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
393
|
## 分面数据诊断相关查询
|
33839b37
tangwang
属性值参与搜索:
|
394
|
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
395
|
### 1. 检查 ES 文档的分面字段数据
|
33839b37
tangwang
属性值参与搜索:
|
396
|
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
397
398
|
#### 1.1 查询特定租户的商品,显示分面相关字段
```bash
|
ccbdf870
tangwang
enriched_attribut...
|
399
|
curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
400
401
402
403
404
405
406
407
408
|
"query": {
"term": { "tenant_id": "162" }
},
"size": 1,
"_source": [
"spu_id", "title", "category1_name", "category2_name",
"category3_name", "specifications", "option1_name",
"option2_name", "option3_name"
]
|
33839b37
tangwang
属性值参与搜索:
|
409
|
}'
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
410
|
```
|
33839b37
tangwang
属性值参与搜索:
|
411
|
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
412
413
|
#### 1.2 验证 category1_name 字段是否有数据
```bash
|
ccbdf870
tangwang
enriched_attribut...
|
414
|
curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
415
416
417
418
419
420
421
422
423
|
"query": {
"bool": {
"filter": [
{ "term": { "tenant_id": "162" } },
{ "exists": { "field": "category1_name" } }
]
}
},
"size": 0
|
33839b37
tangwang
属性值参与搜索:
|
424
|
}'
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
425
|
```
|
33839b37
tangwang
属性值参与搜索:
|
426
|
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
427
428
|
#### 1.3 验证 specifications 字段是否有数据
```bash
|
ccbdf870
tangwang
enriched_attribut...
|
429
|
curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
430
431
432
433
434
435
436
437
438
|
"query": {
"bool": {
"filter": [
{ "term": { "tenant_id": "162" } },
{ "exists": { "field": "specifications" } }
]
}
},
"size": 0
|
33839b37
tangwang
属性值参与搜索:
|
439
|
}'
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
440
|
```
|
33839b37
tangwang
属性值参与搜索:
|
441
|
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
442
|
---
|
33839b37
tangwang
属性值参与搜索:
|
443
|
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
444
445
446
447
|
### 2. 分面聚合查询(Facet Aggregations)
#### 2.1 category1_name 分面聚合
```bash
|
ccbdf870
tangwang
enriched_attribut...
|
448
|
curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
449
450
451
452
453
454
|
"query": { "match_all": {} },
"size": 0,
"aggs": {
"category1_name_facet": {
"terms": { "field": "category1_name", "size": 50 }
}
|
33839b37
tangwang
属性值参与搜索:
|
455
|
}
|
33839b37
tangwang
属性值参与搜索:
|
456
|
}'
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
457
|
```
|
33839b37
tangwang
属性值参与搜索:
|
458
|
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
459
460
|
#### 2.2 specifications.color 分面聚合
```bash
|
ccbdf870
tangwang
enriched_attribut...
|
461
|
curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
462
463
464
465
466
467
468
469
470
471
472
473
|
"query": { "match_all": {} },
"size": 0,
"aggs": {
"specifications_color_facet": {
"nested": { "path": "specifications" },
"aggs": {
"filtered": {
"filter": { "term": { "specifications.name": "color" } },
"aggs": {
"values": { "terms": { "field": "specifications.value", "size": 50 } }
}
}
|
33839b37
tangwang
属性值参与搜索:
|
474
|
}
|
33839b37
tangwang
属性值参与搜索:
|
475
|
}
|
33839b37
tangwang
属性值参与搜索:
|
476
|
}
|
33839b37
tangwang
属性值参与搜索:
|
477
|
}'
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
478
|
```
|
33839b37
tangwang
属性值参与搜索:
|
479
|
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
480
481
|
#### 2.3 specifications.size 分面聚合
```bash
|
ccbdf870
tangwang
enriched_attribut...
|
482
|
curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
483
484
485
486
487
488
489
490
491
492
493
494
|
"query": { "match_all": {} },
"size": 0,
"aggs": {
"specifications_size_facet": {
"nested": { "path": "specifications" },
"aggs": {
"filtered": {
"filter": { "term": { "specifications.name": "size" } },
"aggs": {
"values": { "terms": { "field": "specifications.value", "size": 50 } }
}
}
|
33839b37
tangwang
属性值参与搜索:
|
495
|
}
|
33839b37
tangwang
属性值参与搜索:
|
496
|
}
|
33839b37
tangwang
属性值参与搜索:
|
497
|
}
|
33839b37
tangwang
属性值参与搜索:
|
498
|
}'
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
499
|
```
|
33839b37
tangwang
属性值参与搜索:
|
500
|
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
501
502
|
#### 2.4 specifications.material 分面聚合
```bash
|
ccbdf870
tangwang
enriched_attribut...
|
503
|
curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
504
505
506
507
508
509
510
511
512
513
514
515
|
"query": { "match_all": {} },
"size": 0,
"aggs": {
"specifications_material_facet": {
"nested": { "path": "specifications" },
"aggs": {
"filtered": {
"filter": { "term": { "specifications.name": "material" } },
"aggs": {
"values": { "terms": { "field": "specifications.value", "size": 50 } }
}
}
|
33839b37
tangwang
属性值参与搜索:
|
516
|
}
|
33839b37
tangwang
属性值参与搜索:
|
517
|
}
|
33839b37
tangwang
属性值参与搜索:
|
518
|
}
|
33839b37
tangwang
属性值参与搜索:
|
519
|
}'
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
520
|
```
|
33839b37
tangwang
属性值参与搜索:
|
521
|
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
522
523
|
#### 2.5 综合分面聚合(category + color + size + material)
```bash
|
ccbdf870
tangwang
enriched_attribut...
|
524
|
curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
525
526
527
528
529
530
531
532
533
534
535
|
"query": { "match_all": {} },
"size": 0,
"aggs": {
"category1_name_facet": { "terms": { "field": "category1_name", "size": 50 } },
"specifications_color_facet": {
"nested": { "path": "specifications" },
"aggs": {
"filtered": {
"filter": { "term": { "specifications.name": "color" } },
"aggs": { "values": { "terms": { "field": "specifications.value", "size": 50 } } }
}
|
33839b37
tangwang
属性值参与搜索:
|
536
|
}
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
537
538
539
540
541
542
543
544
|
},
"specifications_size_facet": {
"nested": { "path": "specifications" },
"aggs": {
"filtered": {
"filter": { "term": { "specifications.name": "size" } },
"aggs": { "values": { "terms": { "field": "specifications.value", "size": 50 } } }
}
|
33839b37
tangwang
属性值参与搜索:
|
545
|
}
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
546
547
548
549
550
551
552
553
|
},
"specifications_material_facet": {
"nested": { "path": "specifications" },
"aggs": {
"filtered": {
"filter": { "term": { "specifications.name": "material" } },
"aggs": { "values": { "terms": { "field": "specifications.value", "size": 50 } } }
}
|
33839b37
tangwang
属性值参与搜索:
|
554
|
}
|
33839b37
tangwang
属性值参与搜索:
|
555
|
}
|
33839b37
tangwang
属性值参与搜索:
|
556
|
}
|
33839b37
tangwang
属性值参与搜索:
|
557
|
}'
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
558
559
560
|
```
---
|
33839b37
tangwang
属性值参与搜索:
|
561
|
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
562
|
### 3. 检查 specifications 嵌套字段的详细结构
|
33839b37
tangwang
属性值参与搜索:
|
563
|
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
564
565
|
#### 3.1 查看 specifications 的 name 字段有哪些值
```bash
|
484adbfe
tangwang
adapt ubuntu; con...
|
566
|
curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products/_search?pretty' -H 'Content-Type: application/json' -d '{
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
567
568
569
570
571
572
573
574
|
"query": { "term": { "tenant_id": "162" } },
"size": 0,
"aggs": {
"specifications_names": {
"nested": { "path": "specifications" },
"aggs": {
"name_values": { "terms": { "field": "specifications.name", "size": 20 } }
}
|
33839b37
tangwang
属性值参与搜索:
|
575
|
}
|
33839b37
tangwang
属性值参与搜索:
|
576
|
}
|
33839b37
tangwang
属性值参与搜索:
|
577
|
}'
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
578
|
```
|
33839b37
tangwang
属性值参与搜索:
|
579
|
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
580
581
|
#### 3.2 查看某个商品的完整 specifications 数据
```bash
|
484adbfe
tangwang
adapt ubuntu; con...
|
582
|
curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products/_search?pretty' -H 'Content-Type: application/json' -d '{
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
583
584
585
586
587
588
589
590
591
592
|
"query": {
"bool": {
"filter": [
{ "term": { "tenant_id": "162" } },
{ "exists": { "field": "specifications" } }
]
}
},
"size": 1,
"_source": ["spu_id", "title", "specifications"]
|
33839b37
tangwang
属性值参与搜索:
|
593
|
}'
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
594
|
```
|
33839b37
tangwang
属性值参与搜索:
|
595
|
|
ccbdf870
tangwang
enriched_attribut...
|
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
|
#### 3.3 `enriched_attributes`:`.value.zh` / `.value.en` 的 keyword 精确匹配与 text 全文匹配
> `enriched_attributes` 为 **nested**,检索需包在 `nested` 里。`.keyword` 子字段带 `lowercase` normalizer,英文词建议用小写做 `term`。
**keyword 精确匹配**(示例词:中文 `法式风格`,英文 `long skirt`)
```bash
curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{
"size": 1,
"_source": ["spu_id", "title", "enriched_attributes"],
"query": {
"nested": {
"path": "enriched_attributes",
"query": {
"bool": {
"should": [
{ "term": { "enriched_attributes.value.zh.keyword": "法式风格" } },
{ "term": { "enriched_attributes.value.en.keyword": "long skirt" } }
],
"minimum_should_match": 2
}
}
}
}
}'
```
**text 全文匹配**(经 `index_ik` / `english` 分词;可与上式对照)
```bash
curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{
"size": 1,
"_source": ["spu_id", "title", "enriched_attributes"],
"query": {
"nested": {
"path": "enriched_attributes",
"query": {
"bool": {
"should": [
{ "match": { "enriched_attributes.value.zh": "法式风格" } },
{ "match": { "enriched_attributes.value.en": "long skirt" } }
],
"minimum_should_match": 2
}
}
}
}
}'
```
若需要 **拼写容错**,可在 `match` 上增加 `"fuzziness": "AUTO"`(对英文更常见)。
#### 3.4 `option1_values`:keyword 与 text 分别查 `蓝色` / `blue`
**keyword 精确匹配**
```bash
curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{
"size": 1,
"_source": ["spu_id", "title", "option1_values"],
"query": {
"bool": {
"should": [
{ "term": { "option1_values.zh.keyword": "蓝色" } },
{ "term": { "option1_values.en.keyword": "blue" } }
],
"minimum_should_match": 2
}
}
}'
```
**text 全文匹配**
```bash
curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{
"size": 1,
"_source": ["spu_id", "title", "option1_values"],
"query": {
"bool": {
"should": [
{ "match": { "option1_values.zh": "蓝色" } },
{ "match": { "option1_values.en": "blue" } }
],
"minimum_should_match": 2
}
}
}'
```
#### 3.5 `enriched_tags.zh` / `enriched_tags.en`:keyword 与 text(`高腰` / `high waist`)
**keyword 精确匹配**
```bash
curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{
"size": 1,
"_source": ["spu_id", "title", "enriched_tags"],
"query": {
"bool": {
"should": [
{ "term": { "enriched_tags.zh.keyword": "高腰" } },
{ "term": { "enriched_tags.en.keyword": "high waist" } }
],
"minimum_should_match": 2
}
}
}'
```
**text 全文匹配**
```bash
curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{
"size": 1,
"_source": ["spu_id", "title", "enriched_tags"],
"query": {
"bool": {
"should": [
{ "match": { "enriched_tags.zh": "高腰" } },
{ "match": { "enriched_tags.en": "high waist" } }
],
"minimum_should_match": 2
}
}
}'
```
#### 3.6 `specifications`:`value_keyword` 与 `value_text.zh` / `value_text.en`(`蓝色` / `blue`)
> `specifications` 为 **nested**,`value_keyword` 为整词匹配;`value_text.*` 可同时 `term` 子字段或 `match` 主 text。
```bash
curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{
"size": 1,
"_source": ["spu_id", "title", "specifications"],
"query": {
"nested": {
"path": "specifications",
"query": {
"bool": {
"should": [
{ "term": { "specifications.value_keyword": "蓝色" } },
{ "term": { "specifications.value_keyword": "blue" } },
{ "term": { "specifications.value_text.zh.keyword": "蓝色" } },
{ "term": { "specifications.value_text.en.keyword": "blue" } },
{ "match": { "specifications.value_text.zh": "蓝色" } },
{ "match": { "specifications.value_text.en": "blue" } }
],
"minimum_should_match": 5
}
}
}
}
}'
```
仅查 **keyword 类**(`value_keyword` + `value_text.*.keyword`)时可从上面 `should` 里删掉两条 `match`;仅 **全文** 时可只保留两条 `match`。
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
755
|
---
|
33839b37
tangwang
属性值参与搜索:
|
756
|
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
757
758
759
760
|
### 4. 统计查询
#### 4.1 统计有 category1_name 的文档数量
```bash
|
ccbdf870
tangwang
enriched_attribut...
|
761
|
curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_163/_count?pretty' -H 'Content-Type: application/json' -d '{
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
762
763
764
765
766
767
|
"query": {
"bool": {
"filter": [
{ "exists": { "field": "category1_name" } }
]
}
|
33839b37
tangwang
属性值参与搜索:
|
768
|
}
|
33839b37
tangwang
属性值参与搜索:
|
769
|
}'
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
770
|
```
|
33839b37
tangwang
属性值参与搜索:
|
771
|
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
772
773
|
#### 4.2 统计有 specifications 的文档数量
```bash
|
ccbdf870
tangwang
enriched_attribut...
|
774
|
curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_163/_count?pretty' -H 'Content-Type: application/json' -d '{
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
775
776
777
778
779
780
|
"query": {
"bool": {
"filter": [
{ "exists": { "field": "specifications" } }
]
}
|
33839b37
tangwang
属性值参与搜索:
|
781
|
}
|
33839b37
tangwang
属性值参与搜索:
|
782
|
}'
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
783
|
```
|
33839b37
tangwang
属性值参与搜索:
|
784
|
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
785
|
---
|
33839b37
tangwang
属性值参与搜索:
|
786
|
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
787
|
### 5. 诊断问题场景
|
33839b37
tangwang
属性值参与搜索:
|
788
|
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
789
790
|
#### 5.1 查找没有 category1_name 但有 category 的文档(MySQL 有数据但 ES 没有)
```bash
|
ccbdf870
tangwang
enriched_attribut...
|
791
|
curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
792
793
794
795
796
797
798
799
800
801
802
803
|
"query": {
"bool": {
"filter": [
{ "term": { "tenant_id": "162" } }
],
"must_not": [
{ "exists": { "field": "category1_name" } }
]
}
},
"size": 10,
"_source": ["spu_id", "title", "category_name_text", "category_path"]
|
33839b37
tangwang
属性值参与搜索:
|
804
|
}'
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
805
|
```
|
33839b37
tangwang
属性值参与搜索:
|
806
|
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
807
808
|
#### 5.2 查找有 option 但没有 specifications 的文档(数据转换问题)
```bash
|
ccbdf870
tangwang
enriched_attribut...
|
809
|
curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
810
811
812
813
814
815
816
817
818
819
820
821
822
|
"query": {
"bool": {
"filter": [
{ "term": { "tenant_id": "162" } },
{ "exists": { "field": "option1_name" } }
],
"must_not": [
{ "exists": { "field": "specifications" } }
]
}
},
"size": 10,
"_source": ["spu_id", "title", "option1_name", "option2_name", "option3_name", "specifications"]
|
33839b37
tangwang
属性值参与搜索:
|
823
|
}'
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
824
825
826
|
```
---
|
33839b37
tangwang
属性值参与搜索:
|
827
|
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
828
|
## 重排序示例
|
33839b37
tangwang
属性值参与搜索:
|
829
|
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
830
|
```bash
|
89638140
tangwang
重构 indexer 文档构建接口...
|
831
|
GET /search_products_tenant_170/_search
|
d7d48f52
tangwang
改动(mapping + 灌入结构)
|
832
833
|
{
"query": {
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
834
|
"match": {
|
d7d48f52
tangwang
改动(mapping + 灌入结构)
|
835
836
837
838
839
840
841
|
"title.en": {
"query": "quick brown fox",
"minimum_should_match": "90%"
}
}
},
"rescore": {
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
842
843
|
"window_size": 50,
"query": {
|
d7d48f52
tangwang
改动(mapping + 灌入结构)
|
844
845
846
847
|
"rescore_query": {
"match_phrase": {
"title.en": {
"query": "quick brown fox",
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
848
|
"slop": 50
|
d7d48f52
tangwang
改动(mapping + 灌入结构)
|
849
850
851
852
853
854
|
}
}
}
}
}
}
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
855
|
```
|
272aeabe
tangwang
调参
|
856
|
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
857
|
---
|
272aeabe
tangwang
调参
|
858
|
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
859
860
|
## 检查字段是否存在
|
9df421ed
tangwang
基于eval框架开始调参
|
861
862
863
|
GET search_products_tenant_163/_mapping
GET search_products_tenant_163/_field_caps?fields=*
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
864
|
```bash
|
272aeabe
tangwang
调参
|
865
|
curl -u 'saas:4hOaLaf41y2VuI8y' -X POST \
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
866
867
868
|
'http://localhost:9200/search_products_tenant_163/_count' \
-H 'Content-Type: application/json' \
-d '{
|
272aeabe
tangwang
调参
|
869
|
"query": {
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
870
871
|
"bool": {
"filter": [
|
42024409
tangwang
评估框架-批量打标
|
872
|
{ "exists": { "field": "title_embedding" } }
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
873
874
|
]
}
|
272aeabe
tangwang
调参
|
875
|
}
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
876
|
}'
|
36cf0ef9
tangwang
es索引结果修改
|
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
|
curl -u 'saas:4hOaLaf41y2VuI8y' -X POST \
'http://localhost:9200/search_products_tenant_163/_count' \
-H 'Content-Type: application/json' \
-d '{
"query": {
"nested": {
"path": "image_embedding",
"query": {
"exists": {
"field": "image_embedding.vector"
}
}
}
}
}'
|
c3425429
tangwang
在以下文件中完成精排/融合清理工作...
|
893
|
```
|