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
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# API 快速参考 (v3.0)
## 基础搜索
```bash
POST /search/
{
"query": "芭比娃娃",
"size": 20
}
```
---
## 精确匹配过滤
```bash
{
"filters": {
"categoryName_keyword": "玩具", // 单值
"brandName_keyword": ["乐高", "美泰"] // 多值(OR)
}
}
```
---
## 范围过滤
```bash
{
"range_filters": {
"price": {
"gte": 50, // >=
"lte": 200 // <=
}
}
}
```
**操作符**: `gte` (>=), `gt` (>), `lte` (<=), `lt` (<)
---
## 分面搜索
### 简单模式
```bash
{
"facets": ["categoryName_keyword", "brandName_keyword"]
}
```
### 高级模式
```bash
{
"facets": [
{"field": "categoryName_keyword", "size": 15},
{
"field": "price",
"type": "range",
"ranges": [
{"key": "0-50", "to": 50},
{"key": "50-100", "from": 50, "to": 100}
]
}
]
}
```
---
## 排序
```bash
{
|
cd3799c6
tangwang
tenant2 1w测试数据 mo...
|
79
|
"sort_by": "min_price",
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
"sort_order": "asc" // asc 或 desc
}
```
---
## 布尔表达式
```bash
{
"query": "玩具 AND (乐高 OR 芭比) ANDNOT 电动"
}
```
**操作符优先级**: `()` > `ANDNOT` > `AND` > `OR` > `RANK`
---
## 分页
```bash
{
"size": 20, // 每页数量
"from": 0 // 偏移量(第1页=0,第2页=20)
}
```
---
## 完整示例
```bash
POST /search/
{
"query": "玩具",
"size": 20,
"from": 0,
"filters": {
"categoryName_keyword": ["玩具", "益智玩具"]
},
"range_filters": {
"price": {"gte": 50, "lte": 200}
},
"facets": [
{"field": "brandName_keyword", "size": 15},
{"field": "categoryName_keyword", "size": 15}
],
|
cd3799c6
tangwang
tenant2 1w测试数据 mo...
|
127
|
"sort_by": "min_price",
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
128
129
130
131
132
133
134
135
136
137
138
139
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
|
"sort_order": "asc"
}
```
---
## 响应格式
```json
{
"hits": [
{
"_id": "12345",
"_score": 8.5,
"_source": {...}
}
],
"total": 118,
"max_score": 8.5,
"took_ms": 45,
"facets": [
{
"field": "categoryName_keyword",
"label": "商品类目",
"type": "terms",
"values": [
{
"value": "玩具",
"label": "玩具",
"count": 85,
"selected": false
}
]
}
]
}
```
---
## 其他端点
```bash
POST /search/image
{
"image_url": "https://example.com/image.jpg",
"size": 20
}
GET /search/suggestions?q=芭&size=5
GET /search/instant?q=玩具&size=5
GET /search/{doc_id}
GET /admin/health
GET /admin/config
GET /admin/stats
```
---
## Python 快速示例
```python
import requests
result = requests.post('http://localhost:6002/search/', json={
"query": "玩具",
"filters": {"categoryName_keyword": "玩具"},
"range_filters": {"price": {"gte": 50, "lte": 200}},
"facets": ["brandName_keyword"],
|
cd3799c6
tangwang
tenant2 1w测试数据 mo...
|
200
|
"sort_by": "min_price",
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
"sort_order": "asc"
}).json()
print(f"找到 {result['total']} 个结果")
```
---
## JavaScript 快速示例
```javascript
const result = await fetch('http://localhost:6002/search/', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
query: "玩具",
filters: {categoryName_keyword: "玩具"},
range_filters: {price: {gte: 50, lte: 200}},
facets: ["brandName_keyword"],
|
cd3799c6
tangwang
tenant2 1w测试数据 mo...
|
220
|
sort_by: "min_price",
|
6aa246be
tangwang
问题:Pydantic 应该能自动...
|
221
222
223
224
225
226
227
228
229
230
231
232
|
sort_order: "asc"
})
}).then(r => r.json());
console.log(`找到 ${result.total} 个结果`);
```
---
**详细文档**: [API_DOCUMENTATION.md](API_DOCUMENTATION.md)
**更多示例**: [API_EXAMPLES.md](API_EXAMPLES.md)
**在线文档**: http://localhost:6002/docs
|