6aa246be
tangwang
问题:Pydantic 应该能自动...
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# API 使用示例
本文档提供了搜索引擎 API 的详细使用示例,包括各种常见场景和最佳实践。
---
## 目录
1. [基础搜索](#基础搜索)
2. [过滤器使用](#过滤器使用)
3. [分面搜索](#分面搜索)
4. [排序](#排序)
5. [图片搜索](#图片搜索)
6. [布尔表达式](#布尔表达式)
7. [完整示例](#完整示例)
---
## 基础搜索
### 示例 1:最简单的搜索
```bash
curl -X POST "http://localhost:6002/search/" \
-H "Content-Type: application/json" \
|
f7d3cf70
tangwang
更新文档
|
26
|
-H "X-Tenant-ID: 2" \
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
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
|
-d '{
"query": "芭比娃娃"
}'
```
**响应**:
```json
{
"hits": [...],
"total": 118,
"max_score": 8.5,
"took_ms": 45,
"query_info": {
"original_query": "芭比娃娃",
"detected_language": "zh",
"translations": {"en": "barbie doll"}
}
}
```
### 示例 2:指定返回数量
```bash
curl -X POST "http://localhost:6002/search/" \
-H "Content-Type: application/json" \
|
f7d3cf70
tangwang
更新文档
|
52
|
-H "X-Tenant-ID: 2" \
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
53
|
-d '{
|
f7d3cf70
tangwang
更新文档
|
54
55
|
"query": "手机",
"language": "zh",
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
56
57
58
59
60
61
62
63
64
65
|
"size": 50
}'
```
### 示例 3:分页查询
```bash
# 第1页(0-19)
curl -X POST "http://localhost:6002/search/" \
-H "Content-Type: application/json" \
|
f7d3cf70
tangwang
更新文档
|
66
|
-H "X-Tenant-ID: 2" \
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
67
|
-d '{
|
f7d3cf70
tangwang
更新文档
|
68
69
|
"query": "手机",
"language": "zh",
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
70
71
72
73
74
75
76
|
"size": 20,
"from": 0
}'
# 第2页(20-39)
curl -X POST "http://localhost:6002/search/" \
-H "Content-Type: application/json" \
|
f7d3cf70
tangwang
更新文档
|
77
|
-H "X-Tenant-ID: 2" \
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
78
|
-d '{
|
f7d3cf70
tangwang
更新文档
|
79
80
|
"query": "手机",
"language": "zh",
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
"size": 20,
"from": 20
}'
```
---
## 过滤器使用
### 精确匹配过滤器
#### 示例 1:单值过滤
```bash
curl -X POST "http://localhost:6002/search/" \
-H "Content-Type: application/json" \
|
f7d3cf70
tangwang
更新文档
|
97
|
-H "X-Tenant-ID: 2" \
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
98
|
-d '{
|
f7d3cf70
tangwang
更新文档
|
99
100
|
"query": "手机",
"language": "zh",
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
101
|
"filters": {
|
f7d3cf70
tangwang
更新文档
|
102
|
"category_name": "手机"
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
103
104
105
106
107
108
109
110
111
|
}
}'
```
#### 示例 2:多值过滤(OR 逻辑)
```bash
curl -X POST "http://localhost:6002/search/" \
-H "Content-Type: application/json" \
|
f7d3cf70
tangwang
更新文档
|
112
|
-H "X-Tenant-ID: 2" \
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
113
|
-d '{
|
f7d3cf70
tangwang
更新文档
|
114
115
|
"query": "手机",
"language": "zh",
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
116
|
"filters": {
|
f7d3cf70
tangwang
更新文档
|
117
|
"category_name": ["手机", "电子产品"]
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
118
119
120
121
122
123
124
125
126
127
128
|
}
}'
```
说明:匹配类目为"玩具" **或** "益智玩具" **或** "儿童玩具"的商品。
#### 示例 3:多字段过滤(AND 逻辑)
```bash
curl -X POST "http://localhost:6002/search/" \
-H "Content-Type: application/json" \
|
f7d3cf70
tangwang
更新文档
|
129
|
-H "X-Tenant-ID: 2" \
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
130
|
-d '{
|
f7d3cf70
tangwang
更新文档
|
131
132
|
"query": "手机",
"language": "zh",
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
133
|
"filters": {
|
f7d3cf70
tangwang
更新文档
|
134
135
|
"category_name": "手机",
"vendor_zh.keyword": "奇乐"
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
136
137
138
139
|
}
}'
```
|
f7d3cf70
tangwang
更新文档
|
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
说明:必须同时满足"类目=手机" **并且** "品牌=奇乐"。
#### 示例 4:Specifications 嵌套过滤(单个规格)
```bash
curl -X POST "http://localhost:6002/search/" \
-H "Content-Type: application/json" \
-H "X-Tenant-ID: 2" \
-d '{
"query": "手机",
"language": "zh",
"filters": {
"specifications": {
"name": "color",
"value": "white"
}
}
}'
```
说明:查询规格名称为"color"且值为"white"的商品。
#### 示例 5:Specifications 嵌套过滤(多个规格,OR逻辑)
```bash
curl -X POST "http://localhost:6002/search/" \
-H "Content-Type: application/json" \
-H "X-Tenant-ID: 2" \
-d '{
"query": "手机",
"language": "zh",
"filters": {
"specifications": [
{"name": "color", "value": "white"},
{"name": "size", "value": "256GB"}
]
}
}'
```
说明:查询满足任意一个规格的商品(color=white **或** size=256GB)。
#### 示例 6:组合过滤(包含 specifications)
```bash
curl -X POST "http://localhost:6002/search/" \
-H "Content-Type: application/json" \
-H "X-Tenant-ID: 2" \
-d '{
"query": "手机",
"language": "zh",
"filters": {
"category_name": "手机",
"specifications": {
"name": "color",
"value": "white"
}
}
}'
```
说明:同时满足类目=手机 **并且** color=white。
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
202
203
204
205
206
207
208
209
|
### 范围过滤器
#### 示例 1:价格范围
```bash
curl -X POST "http://localhost:6002/search/" \
-H "Content-Type: application/json" \
|
f7d3cf70
tangwang
更新文档
|
210
|
-H "X-Tenant-ID: 2" \
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
211
|
-d '{
|
f7d3cf70
tangwang
更新文档
|
212
213
|
"query": "手机",
"language": "zh",
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
214
|
"range_filters": {
|
f7d3cf70
tangwang
更新文档
|
215
|
"min_price": {
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
"gte": 50,
"lte": 200
}
}
}'
```
说明:价格在 50-200 元之间(包含边界)。
#### 示例 2:只设置下限
```bash
curl -X POST "http://localhost:6002/search/" \
-H "Content-Type: application/json" \
|
f7d3cf70
tangwang
更新文档
|
230
|
-H "X-Tenant-ID: 2" \
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
231
|
-d '{
|
f7d3cf70
tangwang
更新文档
|
232
233
|
"query": "手机",
"language": "zh",
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
234
|
"range_filters": {
|
f7d3cf70
tangwang
更新文档
|
235
|
"min_price": {
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
236
237
238
239
240
241
242
243
244
245
246
247
248
|
"gte": 100
}
}
}'
```
说明:价格 ≥ 100 元。
#### 示例 3:只设置上限
```bash
curl -X POST "http://localhost:6002/search/" \
-H "Content-Type: application/json" \
|
f7d3cf70
tangwang
更新文档
|
249
|
-H "X-Tenant-ID: 2" \
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
250
|
-d '{
|
f7d3cf70
tangwang
更新文档
|
251
252
|
"query": "手机",
"language": "zh",
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
253
|
"range_filters": {
|
f7d3cf70
tangwang
更新文档
|
254
|
"min_price": {
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
255
256
257
258
259
260
261
262
263
264
265
266
267
|
"lt": 50
}
}
}'
```
说明:价格 < 50 元(不包含50)。
#### 示例 4:多字段范围过滤
```bash
curl -X POST "http://localhost:6002/search/" \
-H "Content-Type: application/json" \
|
f7d3cf70
tangwang
更新文档
|
268
|
-H "X-Tenant-ID: 2" \
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
269
|
-d '{
|
f7d3cf70
tangwang
更新文档
|
270
271
|
"query": "手机",
"language": "zh",
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
272
|
"range_filters": {
|
f7d3cf70
tangwang
更新文档
|
273
|
"min_price": {
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
|
"gte": 50,
"lte": 200
},
"days_since_last_update": {
"lte": 30
}
}
}'
```
说明:价格在 50-200 元 **并且** 最近30天内更新过。
### 组合过滤器
```bash
curl -X POST "http://localhost:6002/search/" \
-H "Content-Type: application/json" \
|
f7d3cf70
tangwang
更新文档
|
291
|
-H "X-Tenant-ID: 2" \
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
292
|
-d '{
|
f7d3cf70
tangwang
更新文档
|
293
294
|
"query": "手机",
"language": "zh",
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
295
|
"filters": {
|
f7d3cf70
tangwang
更新文档
|
296
297
|
"category_name": ["手机", "电子产品"],
"vendor_zh.keyword": "品牌A"
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
298
299
|
},
"range_filters": {
|
f7d3cf70
tangwang
更新文档
|
300
|
"min_price": {
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
|
"gte": 50,
"lte": 500
}
}
}'
```
说明:类目是"玩具"或"益智玩具" **并且** 品牌是"乐高" **并且** 价格在 50-500 元之间。
---
## 分面搜索
### 简单模式
#### 示例 1:基础分面
```bash
curl -X POST "http://localhost:6002/search/" \
-H "Content-Type: application/json" \
|
f7d3cf70
tangwang
更新文档
|
321
|
-H "X-Tenant-ID: 2" \
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
322
|
-d '{
|
f7d3cf70
tangwang
更新文档
|
323
324
|
"query": "手机",
"language": "zh",
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
325
|
"size": 20,
|
f7d3cf70
tangwang
更新文档
|
326
|
"facets": ["category1_name", "category2_name", "specifications"]
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
327
328
329
330
331
332
|
}'
```
**响应**:
```json
{
|
f7d3cf70
tangwang
更新文档
|
333
|
"results": [...],
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
334
335
336
|
"total": 118,
"facets": [
{
|
f7d3cf70
tangwang
更新文档
|
337
338
|
"field": "category1_name",
"label": "category1_name",
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
339
340
|
"type": "terms",
"values": [
|
f7d3cf70
tangwang
更新文档
|
341
342
|
{"value": "手机", "count": 85, "selected": false},
{"value": "电子产品", "count": 33, "selected": false}
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
343
344
345
|
]
},
{
|
f7d3cf70
tangwang
更新文档
|
346
347
|
"field": "specifications.color",
"label": "color",
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
348
349
|
"type": "terms",
"values": [
|
f7d3cf70
tangwang
更新文档
|
350
351
352
353
354
355
356
357
358
359
360
|
{"value": "white", "count": 50, "selected": false},
{"value": "black", "count": 30, "selected": false}
]
},
{
"field": "specifications.size",
"label": "size",
"type": "terms",
"values": [
{"value": "256GB", "count": 40, "selected": false},
{"value": "512GB", "count": 20, "selected": false}
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
361
362
363
364
365
366
|
]
}
]
}
```
|
f7d3cf70
tangwang
更新文档
|
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
|
#### 示例 2:Specifications 分面(所有规格名称)
```bash
curl -X POST "http://localhost:6002/search/" \
-H "Content-Type: application/json" \
-H "X-Tenant-ID: 2" \
-d '{
"query": "手机",
"language": "zh",
"facets": ["specifications"]
}'
```
说明:返回所有规格名称(name)及其对应的值(value)列表。
#### 示例 3:Specifications 分面(指定规格名称)
```bash
curl -X POST "http://localhost:6002/search/" \
-H "Content-Type: application/json" \
-H "X-Tenant-ID: 2" \
-d '{
"query": "手机",
"language": "zh",
"facets": ["specifications.color", "specifications.size"]
}'
```
说明:只返回指定规格名称的值列表。
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
397
398
399
400
401
402
403
|
### 高级模式
#### 示例 1:自定义分面大小
```bash
curl -X POST "http://localhost:6002/search/" \
-H "Content-Type: application/json" \
|
f7d3cf70
tangwang
更新文档
|
404
|
-H "X-Tenant-ID: 2" \
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
405
|
-d '{
|
f7d3cf70
tangwang
更新文档
|
406
407
|
"query": "手机",
"language": "zh",
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
408
409
|
"facets": [
{
|
f7d3cf70
tangwang
更新文档
|
410
|
"field": "category1_name",
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
411
412
413
414
|
"size": 20,
"type": "terms"
},
{
|
f7d3cf70
tangwang
更新文档
|
415
|
"field": "category2_name",
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
416
417
418
419
420
421
422
423
424
425
426
427
|
"size": 30,
"type": "terms"
}
]
}'
```
#### 示例 2:范围分面
```bash
curl -X POST "http://localhost:6002/search/" \
-H "Content-Type: application/json" \
|
f7d3cf70
tangwang
更新文档
|
428
|
-H "X-Tenant-ID: 2" \
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
429
|
-d '{
|
f7d3cf70
tangwang
更新文档
|
430
431
|
"query": "手机",
"language": "zh",
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
|
"facets": [
{
"field": "price",
"type": "range",
"ranges": [
{"key": "0-50", "to": 50},
{"key": "50-100", "from": 50, "to": 100},
{"key": "100-200", "from": 100, "to": 200},
{"key": "200+", "from": 200}
]
}
]
}'
```
**响应**:
```json
{
"facets": [
{
"field": "price",
"label": "price",
"type": "range",
"values": [
{"value": "0-50", "count": 23, "selected": false},
{"value": "50-100", "count": 45, "selected": false},
{"value": "100-200", "count": 38, "selected": false},
{"value": "200+", "count": 12, "selected": false}
]
}
]
}
```
#### 示例 3:混合分面(Terms + Range)
```bash
curl -X POST "http://localhost:6002/search/" \
-H "Content-Type: application/json" \
|
f7d3cf70
tangwang
更新文档
|
471
|
-H "X-Tenant-ID: 2" \
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
472
|
-d '{
|
f7d3cf70
tangwang
更新文档
|
473
474
|
"query": "手机",
"language": "zh",
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
475
|
"facets": [
|
cadc77b6
tangwang
索引字段名、变量名、API数据结构...
|
476
477
|
{"field": "category.keyword", "size": 15},
{"field": "vendor.keyword", "size": 15},
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
|
{
"field": "price",
"type": "range",
"ranges": [
{"key": "低价", "to": 50},
{"key": "中价", "from": 50, "to": 200},
{"key": "高价", "from": 200}
]
}
]
}'
```
---
## 排序
### 示例 1:按价格排序(升序)
```bash
curl -X POST "http://localhost:6002/search/" \
-H "Content-Type: application/json" \
|
f7d3cf70
tangwang
更新文档
|
500
|
-H "X-Tenant-ID: 2" \
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
501
|
-d '{
|
f7d3cf70
tangwang
更新文档
|
502
503
|
"query": "手机",
"language": "zh",
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
504
|
"size": 20,
|
cd3799c6
tangwang
tenant2 1w测试数据 mo...
|
505
|
"sort_by": "min_price",
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
506
507
508
509
510
511
512
513
514
|
"sort_order": "asc"
}'
```
### 示例 2:按创建时间排序(降序)
```bash
curl -X POST "http://localhost:6002/search/" \
-H "Content-Type: application/json" \
|
f7d3cf70
tangwang
更新文档
|
515
|
-H "X-Tenant-ID: 2" \
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
516
|
-d '{
|
f7d3cf70
tangwang
更新文档
|
517
518
|
"query": "手机",
"language": "zh",
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
519
520
521
522
523
524
525
526
527
528
529
|
"size": 20,
"sort_by": "create_time",
"sort_order": "desc"
}'
```
### 示例 3:排序+过滤
```bash
curl -X POST "http://localhost:6002/search/" \
-H "Content-Type: application/json" \
|
f7d3cf70
tangwang
更新文档
|
530
|
-H "X-Tenant-ID: 2" \
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
531
|
-d '{
|
f7d3cf70
tangwang
更新文档
|
532
533
|
"query": "手机",
"language": "zh",
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
534
|
"filters": {
|
cadc77b6
tangwang
索引字段名、变量名、API数据结构...
|
535
|
"category.keyword": "益智玩具"
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
536
|
},
|
cd3799c6
tangwang
tenant2 1w测试数据 mo...
|
537
|
"sort_by": "min_price",
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
538
539
540
541
542
543
544
545
546
547
548
549
550
|
"sort_order": "asc"
}'
```
---
## 图片搜索
### 示例 1:基础图片搜索
```bash
curl -X POST "http://localhost:6002/search/image" \
-H "Content-Type: application/json" \
|
f7d3cf70
tangwang
更新文档
|
551
|
-H "X-Tenant-ID: 2" \
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
552
553
554
555
556
557
558
559
560
561
562
|
-d '{
"image_url": "https://example.com/barbie.jpg",
"size": 20
}'
```
### 示例 2:图片搜索+过滤器
```bash
curl -X POST "http://localhost:6002/search/image" \
-H "Content-Type: application/json" \
|
f7d3cf70
tangwang
更新文档
|
563
|
-H "X-Tenant-ID: 2" \
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
564
565
566
567
|
-d '{
"image_url": "https://example.com/barbie.jpg",
"size": 20,
"filters": {
|
f7d3cf70
tangwang
更新文档
|
568
|
"category_name": "手机"
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
569
570
|
},
"range_filters": {
|
f7d3cf70
tangwang
更新文档
|
571
|
"min_price": {
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
|
"lte": 100
}
}
}'
```
---
## 布尔表达式
### 示例 1:AND 查询
```bash
curl -X POST "http://localhost:6002/search/" \
-H "Content-Type: application/json" \
|
f7d3cf70
tangwang
更新文档
|
587
|
-H "X-Tenant-ID: 2" \
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
588
589
590
591
592
593
594
595
596
597
598
599
|
-d '{
"query": "玩具 AND 乐高"
}'
```
说明:必须同时包含"玩具"和"乐高"。
### 示例 2:OR 查询
```bash
curl -X POST "http://localhost:6002/search/" \
-H "Content-Type: application/json" \
|
f7d3cf70
tangwang
更新文档
|
600
|
-H "X-Tenant-ID: 2" \
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
601
602
603
604
605
606
607
608
609
610
611
612
|
-d '{
"query": "芭比 OR 娃娃"
}'
```
说明:包含"芭比"或"娃娃"即可。
### 示例 3:ANDNOT 查询(排除)
```bash
curl -X POST "http://localhost:6002/search/" \
-H "Content-Type: application/json" \
|
f7d3cf70
tangwang
更新文档
|
613
|
-H "X-Tenant-ID: 2" \
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
614
615
616
617
618
619
620
621
622
623
624
625
|
-d '{
"query": "玩具 ANDNOT 电动"
}'
```
说明:包含"玩具"但不包含"电动"。
### 示例 4:复杂布尔表达式
```bash
curl -X POST "http://localhost:6002/search/" \
-H "Content-Type: application/json" \
|
f7d3cf70
tangwang
更新文档
|
626
|
-H "X-Tenant-ID: 2" \
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
627
628
629
630
631
632
633
634
635
636
637
638
|
-d '{
"query": "玩具 AND (乐高 OR 芭比) ANDNOT 电动"
}'
```
说明:必须包含"玩具",并且包含"乐高"或"芭比",但不包含"电动"。
### 示例 5:域查询
```bash
curl -X POST "http://localhost:6002/search/" \
-H "Content-Type: application/json" \
|
f7d3cf70
tangwang
更新文档
|
639
|
-H "X-Tenant-ID: 2" \
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
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
|
-d '{
"query": "brand:乐高"
}'
```
说明:在品牌域中搜索"乐高"。
---
## 完整示例
### Python 完整示例
```python
#!/usr/bin/env python3
import requests
import json
API_URL = "http://localhost:6002/search/"
def search_products(
query,
size=20,
from_=0,
filters=None,
range_filters=None,
facets=None,
sort_by=None,
sort_order="desc",
debug=False
):
"""执行搜索查询"""
payload = {
"query": query,
"size": size,
"from": from_
}
if filters:
payload["filters"] = filters
if range_filters:
payload["range_filters"] = range_filters
if facets:
payload["facets"] = facets
if sort_by:
payload["sort_by"] = sort_by
payload["sort_order"] = sort_order
if debug:
payload["debug"] = debug
response = requests.post(API_URL, json=payload)
response.raise_for_status()
return response.json()
# 示例 1:简单搜索
result = search_products("芭比娃娃", size=10)
print(f"找到 {result['total']} 个结果")
for hit in result['hits'][:3]:
product = hit['_source']
print(f" - {product['name']}: ¥{product.get('price', 'N/A')}")
# 示例 2:带过滤和分面的搜索
result = search_products(
|
f7d3cf70
tangwang
更新文档
|
704
|
query="手机",
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
705
|
size=20,
|
f7d3cf70
tangwang
更新文档
|
706
|
language="zh",
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
707
|
filters={
|
f7d3cf70
tangwang
更新文档
|
708
709
|
"category_name": "手机",
"specifications": {"name": "color", "value": "white"}
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
710
711
|
},
range_filters={
|
f7d3cf70
tangwang
更新文档
|
712
|
"min_price": {"gte": 50, "lte": 200}
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
713
714
|
},
facets=[
|
f7d3cf70
tangwang
更新文档
|
715
716
717
718
|
{"field": "category1_name", "size": 15},
{"field": "category2_name", "size": 15},
"specifications.color",
"specifications.size",
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
719
|
{
|
f7d3cf70
tangwang
更新文档
|
720
|
"field": "min_price",
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
721
722
723
724
725
726
727
728
729
|
"type": "range",
"ranges": [
{"key": "0-50", "to": 50},
{"key": "50-100", "from": 50, "to": 100},
{"key": "100-200", "from": 100, "to": 200},
{"key": "200+", "from": 200}
]
}
],
|
cd3799c6
tangwang
tenant2 1w测试数据 mo...
|
730
|
sort_by="min_price",
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
|
sort_order="asc"
)
# 显示分面结果
print(f"\n分面统计:")
for facet in result.get('facets', []):
print(f"\n{facet['label']} ({facet['type']}):")
for value in facet['values'][:5]:
selected_mark = "✓" if value['selected'] else " "
print(f" [{selected_mark}] {value['label']}: {value['count']}")
# 示例 3:分页查询
page = 1
page_size = 20
total_pages = 5
for page in range(1, total_pages + 1):
result = search_products(
query="玩具",
size=page_size,
from_=(page - 1) * page_size
)
print(f"\n第 {page} 页:")
for hit in result['hits']:
product = hit['_source']
print(f" - {product['name']}")
```
### JavaScript 完整示例
```javascript
// 搜索引擎客户端
class SearchClient {
constructor(baseUrl) {
this.baseUrl = baseUrl;
}
async search({
query,
size = 20,
from = 0,
filters = null,
rangeFilters = null,
facets = null,
sortBy = null,
sortOrder = 'desc',
debug = false
}) {
const payload = {
query,
size,
from
};
if (filters) payload.filters = filters;
if (rangeFilters) payload.range_filters = rangeFilters;
if (facets) payload.facets = facets;
if (sortBy) {
payload.sort_by = sortBy;
payload.sort_order = sortOrder;
}
if (debug) payload.debug = debug;
const response = await fetch(`${this.baseUrl}/search/`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(payload)
});
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}
return await response.json();
}
async searchByImage(imageUrl, options = {}) {
const payload = {
image_url: imageUrl,
size: options.size || 20,
filters: options.filters || null,
range_filters: options.rangeFilters || null
};
const response = await fetch(`${this.baseUrl}/search/image`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(payload)
});
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}
return await response.json();
}
}
// 使用示例
const client = new SearchClient('http://localhost:6002');
// 简单搜索
const result1 = await client.search({
query: "芭比娃娃",
size: 20
});
console.log(`找到 ${result1.total} 个结果`);
|
f7d3cf70
tangwang
更新文档
|
843
|
// 带过滤和分面的搜索(包含规格)
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
844
|
const result2 = await client.search({
|
f7d3cf70
tangwang
更新文档
|
845
846
|
query: "手机",
language: "zh",
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
847
848
|
size: 20,
filters: {
|
f7d3cf70
tangwang
更新文档
|
849
850
|
category_name: "手机",
specifications: { name: "color", value: "white" }
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
851
852
|
},
rangeFilters: {
|
f7d3cf70
tangwang
更新文档
|
853
|
min_price: { gte: 50, lte: 200 }
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
854
855
|
},
facets: [
|
f7d3cf70
tangwang
更新文档
|
856
857
858
|
"category1_name",
"specifications.color",
"specifications.size"
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
859
|
],
|
f7d3cf70
tangwang
更新文档
|
860
|
sortBy: "min_price",
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
|
sortOrder: "asc"
});
// 显示分面结果
result2.facets.forEach(facet => {
console.log(`\n${facet.label}:`);
facet.values.forEach(value => {
const selected = value.selected ? '✓' : ' ';
console.log(` [${selected}] ${value.label}: ${value.count}`);
});
});
// 显示商品
result2.hits.forEach(hit => {
const product = hit._source;
console.log(`${product.name} - ¥${product.price}`);
});
```
### 前端完整示例(Vue.js 风格)
```javascript
// 搜索组件
const SearchComponent = {
data() {
return {
query: '',
results: [],
facets: [],
filters: {},
rangeFilters: {},
total: 0,
currentPage: 1,
pageSize: 20
};
},
methods: {
async search() {
const response = await fetch('http://localhost:6002/search/', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
query: this.query,
size: this.pageSize,
from: (this.currentPage - 1) * this.pageSize,
filters: this.filters,
range_filters: this.rangeFilters,
facets: [
|
cadc77b6
tangwang
索引字段名、变量名、API数据结构...
|
909
910
|
{ field: 'category.keyword', size: 15 },
{ field: 'vendor.keyword', size: 15 }
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
|
]
})
});
const data = await response.json();
this.results = data.hits;
this.facets = data.facets || [];
this.total = data.total;
},
toggleFilter(field, value) {
if (!this.filters[field]) {
this.filters[field] = [];
}
const index = this.filters[field].indexOf(value);
if (index > -1) {
this.filters[field].splice(index, 1);
if (this.filters[field].length === 0) {
delete this.filters[field];
}
} else {
this.filters[field].push(value);
}
this.currentPage = 1;
this.search();
},
setPriceRange(min, max) {
if (min !== null || max !== null) {
this.rangeFilters.price = {};
if (min !== null) this.rangeFilters.price.gte = min;
if (max !== null) this.rangeFilters.price.lte = max;
} else {
delete this.rangeFilters.price;
}
this.currentPage = 1;
this.search();
}
}
};
```
---
## 调试与优化
### 启用调试模式
```bash
curl -X POST "http://localhost:6002/search/" \
-H "Content-Type: application/json" \
|
f7d3cf70
tangwang
更新文档
|
964
|
-H "X-Tenant-ID: 2" \
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
965
|
-d '{
|
f7d3cf70
tangwang
更新文档
|
966
967
|
"query": "手机",
"language": "zh",
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
|
"debug": true
}'
```
**响应包含调试信息**:
```json
{
"hits": [...],
"total": 118,
"debug_info": {
"query_analysis": {
"original_query": "玩具",
"normalized_query": "玩具",
"rewritten_query": "玩具",
"detected_language": "zh",
"translations": {"en": "toy"}
},
"es_query": {
"query": {...},
"size": 10
},
"stage_timings": {
"query_parsing": 5.3,
"elasticsearch_search": 35.1,
"result_processing": 4.8
}
}
}
```
### 设置最小分数阈值
```bash
curl -X POST "http://localhost:6002/search/" \
-H "Content-Type: application/json" \
|
f7d3cf70
tangwang
更新文档
|
1003
|
-H "X-Tenant-ID: 2" \
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
1004
|
-d '{
|
f7d3cf70
tangwang
更新文档
|
1005
1006
|
"query": "手机",
"language": "zh",
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
|
"min_score": 5.0
}'
```
说明:只返回相关性分数 ≥ 5.0 的结果。
---
## 常见使用场景
### 场景 1:电商分类页
```bash
# 显示某个类目下的所有商品,按价格排序,提供品牌筛选
curl -X POST "http://localhost:6002/search/" \
-H "Content-Type: application/json" \
|
f7d3cf70
tangwang
更新文档
|
1023
|
-H "X-Tenant-ID: 2" \
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
1024
1025
1026
|
-d '{
"query": "*",
"filters": {
|
f7d3cf70
tangwang
更新文档
|
1027
|
"category_name": "手机"
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
1028
1029
|
},
"facets": [
|
cadc77b6
tangwang
索引字段名、变量名、API数据结构...
|
1030
|
{"field": "vendor.keyword", "size": 20},
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
|
{
"field": "price",
"type": "range",
"ranges": [
{"key": "0-50", "to": 50},
{"key": "50-100", "from": 50, "to": 100},
{"key": "100-200", "from": 100, "to": 200},
{"key": "200+", "from": 200}
]
}
],
|
cd3799c6
tangwang
tenant2 1w测试数据 mo...
|
1042
|
"sort_by": "min_price",
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
1043
1044
1045
1046
1047
1048
1049
1050
|
"sort_order": "asc",
"size": 24
}'
```
### 场景 2:搜索结果页
```bash
|
f7d3cf70
tangwang
更新文档
|
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
|
# 用户搜索关键词,提供筛选和排序(包含规格分面)
curl -X POST "http://localhost:6002/search/" \
-H "Content-Type: application/json" \
-H "X-Tenant-ID: 2" \
-d '{
"query": "手机",
"language": "zh",
"facets": [
{"field": "category1_name", "size": 10},
{"field": "category2_name", "size": 10},
"specifications.color",
"specifications.size",
{
"field": "min_price",
"type": "range",
"ranges": [
{"key": "0-50", "to": 50},
{"key": "50-100", "from": 50, "to": 100},
{"key": "100+", "from": 100}
]
}
],
"size": 20
}'
```
### 场景 2.1:带规格过滤的搜索结果页
```bash
# 用户搜索并选择了规格筛选条件
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
1081
1082
|
curl -X POST "http://localhost:6002/search/" \
-H "Content-Type: application/json" \
|
f7d3cf70
tangwang
更新文档
|
1083
|
-H "X-Tenant-ID: 2" \
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
1084
|
-d '{
|
f7d3cf70
tangwang
更新文档
|
1085
1086
1087
1088
1089
1090
1091
1092
1093
|
"query": "手机",
"language": "zh",
"filters": {
"category_name": "手机",
"specifications": {
"name": "color",
"value": "white"
}
},
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
1094
|
"facets": [
|
f7d3cf70
tangwang
更新文档
|
1095
1096
1097
|
"category1_name",
"specifications.color",
"specifications.size"
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
|
],
"size": 20
}'
```
### 场景 3:促销专区
```bash
# 显示特定价格区间的商品
curl -X POST "http://localhost:6002/search/" \
-H "Content-Type: application/json" \
|
f7d3cf70
tangwang
更新文档
|
1109
|
-H "X-Tenant-ID: 2" \
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
1110
1111
1112
|
-d '{
"query": "*",
"range_filters": {
|
f7d3cf70
tangwang
更新文档
|
1113
|
"min_price": {
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
1114
1115
1116
1117
|
"gte": 50,
"lte": 100
}
},
|
f7d3cf70
tangwang
更新文档
|
1118
|
"facets": ["category1_name", "category2_name", "specifications"],
|
cd3799c6
tangwang
tenant2 1w测试数据 mo...
|
1119
|
"sort_by": "min_price",
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
|
"sort_order": "asc",
"size": 50
}'
```
### 场景 4:新品推荐
```bash
# 最近更新的商品
curl -X POST "http://localhost:6002/search/" \
-H "Content-Type: application/json" \
|
f7d3cf70
tangwang
更新文档
|
1131
|
-H "X-Tenant-ID: 2" \
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
|
-d '{
"query": "*",
"range_filters": {
"days_since_last_update": {
"lte": 7
}
},
"sort_by": "create_time",
"sort_order": "desc",
"size": 20
}'
```
---
## 错误处理
### 示例 1:参数错误
```bash
# 错误:range_filters 缺少操作符
curl -X POST "http://localhost:6002/search/" \
-H "Content-Type: application/json" \
|
f7d3cf70
tangwang
更新文档
|
1155
|
-H "X-Tenant-ID: 2" \
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
1156
|
-d '{
|
f7d3cf70
tangwang
更新文档
|
1157
1158
|
"query": "手机",
"language": "zh",
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
1159
|
"range_filters": {
|
f7d3cf70
tangwang
更新文档
|
1160
|
"min_price": {}
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
|
}
}'
```
**响应**:
```json
{
"error": "Validation error",
"detail": "至少需要指定一个范围边界(gte, gt, lte, lt)",
"timestamp": 1699800000
}
```
### 示例 2:空查询
```bash
# 错误:query 为空
curl -X POST "http://localhost:6002/search/" \
-H "Content-Type: application/json" \
|
f7d3cf70
tangwang
更新文档
|
1180
|
-H "X-Tenant-ID: 2" \
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
|
-d '{
"query": ""
}'
```
**响应**:
```json
{
"error": "Validation error",
"detail": "query field required",
"timestamp": 1699800000
}
```
---
## 性能优化建议
### 1. 合理使用分面
```bash
# ❌ 不推荐:请求太多分面
{
"facets": [
{"field": "field1", "size": 100},
{"field": "field2", "size": 100},
{"field": "field3", "size": 100},
// ... 10+ facets
]
}
# ✅ 推荐:只请求必要的分面
{
"facets": [
|
cadc77b6
tangwang
索引字段名、变量名、API数据结构...
|
1215
1216
|
{"field": "category.keyword", "size": 15},
{"field": "vendor.keyword", "size": 15}
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
|
]
}
```
### 2. 控制返回数量
```bash
# ❌ 不推荐:一次返回太多
{
"size": 100
}
# ✅ 推荐:分页查询
{
"size": 20,
"from": 0
}
```
### 3. 使用适当的过滤器
```bash
# ✅ 推荐:先过滤后搜索
{
"query": "玩具",
"filters": {
|
cadc77b6
tangwang
索引字段名、变量名、API数据结构...
|
1243
|
"category.keyword": "玩具"
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
|
}
}
```
---
## 高级技巧
### 技巧 1:获取所有类目
```bash
# 使用通配符查询 + 分面
curl -X POST "http://localhost:6002/search/" \
-H "Content-Type: application/json" \
|
f7d3cf70
tangwang
更新文档
|
1258
|
-H "X-Tenant-ID: 2" \
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
1259
1260
1261
1262
|
-d '{
"query": "*",
"size": 0,
"facets": [
|
cadc77b6
tangwang
索引字段名、变量名、API数据结构...
|
1263
|
{"field": "category.keyword", "size": 100}
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
1264
1265
1266
1267
1268
1269
1270
1271
1272
|
]
}'
```
### 技巧 2:价格分布统计
```bash
curl -X POST "http://localhost:6002/search/" \
-H "Content-Type: application/json" \
|
f7d3cf70
tangwang
更新文档
|
1273
|
-H "X-Tenant-ID: 2" \
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
1274
|
-d '{
|
f7d3cf70
tangwang
更新文档
|
1275
1276
|
"query": "手机",
"language": "zh",
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
|
"size": 0,
"facets": [
{
"field": "price",
"type": "range",
"ranges": [
{"key": "0-50", "to": 50},
{"key": "50-100", "from": 50, "to": 100},
{"key": "100-200", "from": 100, "to": 200},
{"key": "200-500", "from": 200, "to": 500},
{"key": "500+", "from": 500}
]
}
]
}'
```
### 技巧 3:组合多种查询类型
```bash
# 布尔表达式 + 过滤器 + 分面 + 排序
curl -X POST "http://localhost:6002/search/" \
-H "Content-Type: application/json" \
|
f7d3cf70
tangwang
更新文档
|
1300
|
-H "X-Tenant-ID: 2" \
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
1301
1302
1303
|
-d '{
"query": "(玩具 OR 游戏) AND 儿童 ANDNOT 电子",
"filters": {
|
cadc77b6
tangwang
索引字段名、变量名、API数据结构...
|
1304
|
"category.keyword": ["玩具", "益智玩具"]
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
1305
1306
|
},
"range_filters": {
|
f7d3cf70
tangwang
更新文档
|
1307
|
"min_price": {"gte": 20, "lte": 100},
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
1308
1309
1310
|
"days_since_last_update": {"lte": 30}
},
"facets": [
|
cadc77b6
tangwang
索引字段名、变量名、API数据结构...
|
1311
|
{"field": "vendor.keyword", "size": 20}
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
1312
|
],
|
cd3799c6
tangwang
tenant2 1w测试数据 mo...
|
1313
|
"sort_by": "min_price",
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
|
"sort_order": "asc",
"size": 20
}'
```
---
## 测试数据
如果你需要测试数据,可以使用以下查询:
```bash
# 测试类目:玩具
curl -X POST "http://localhost:6002/search/" \
-H "Content-Type: application/json" \
|
f7d3cf70
tangwang
更新文档
|
1329
|
-H "X-Tenant-ID: 2" \
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
1330
1331
1332
1333
1334
|
-d '{"query": "玩具", "size": 5}'
# 测试品牌:乐高
curl -X POST "http://localhost:6002/search/" \
-H "Content-Type: application/json" \
|
f7d3cf70
tangwang
更新文档
|
1335
|
-H "X-Tenant-ID: 2" \
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
1336
1337
1338
1339
1340
|
-d '{"query": "brand:乐高", "size": 5}'
# 测试布尔表达式
curl -X POST "http://localhost:6002/search/" \
-H "Content-Type: application/json" \
|
f7d3cf70
tangwang
更新文档
|
1341
|
-H "X-Tenant-ID: 2" \
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
1342
1343
1344
1345
1346
1347
1348
1349
|
-d '{"query": "玩具 AND 乐高", "size": 5}'
```
---
**文档版本**: 3.0
**最后更新**: 2024-11-12
**相关文档**: `API_DOCUMENTATION.md`
|