Blame view

api/routes/search.py 17.2 KB
be52af70   tangwang   first commit
1
2
3
4
  """
  Search API routes.
  """
  
16c42787   tangwang   feat: implement r...
5
  from fastapi import APIRouter, HTTPException, Query, Request
be52af70   tangwang   first commit
6
  from typing import Optional
16c42787   tangwang   feat: implement r...
7
  import uuid
28e57bb1   tangwang   日志体系优化
8
9
10
  import hashlib
  import json
  import logging
be52af70   tangwang   first commit
11
12
13
14
15
  
  from ..models import (
      SearchRequest,
      ImageSearchRequest,
      SearchResponse,
6aa246be   tangwang   问题:Pydantic 应该能自动...
16
      SearchSuggestResponse,
be52af70   tangwang   first commit
17
18
19
      DocumentResponse,
      ErrorResponse
  )
16c42787   tangwang   feat: implement r...
20
  from context.request_context import create_request_context, set_current_request_context, clear_current_request_context
985752f5   tangwang   1. 前端调试功能
21
  from indexer.mapping_generator import get_tenant_index_name
be52af70   tangwang   first commit
22
23
  
  router = APIRouter(prefix="/search", tags=["search"])
28e57bb1   tangwang   日志体系优化
24
25
26
27
28
29
30
31
32
  backend_verbose_logger = logging.getLogger("backend.verbose")
  
  
  def _log_backend_verbose(payload: dict) -> None:
      if not backend_verbose_logger.handlers:
          return
      backend_verbose_logger.info(
          json.dumps(payload, ensure_ascii=False, separators=(",", ":"))
      )
be52af70   tangwang   first commit
33
34
  
  
16c42787   tangwang   feat: implement r...
35
36
37
38
39
  def extract_request_info(request: Request) -> tuple[str, str]:
      """Extract request ID and user ID from HTTP request"""
      # Try to get request ID from headers
      reqid = request.headers.get('X-Request-ID') or str(uuid.uuid4())[:8]
  
99bea633   tangwang   add logs
40
41
      # Try to get user ID from headers; if not found, use "-1" for correlation
      uid = request.headers.get('X-User-ID') or request.headers.get('User-ID') or "-1"
16c42787   tangwang   feat: implement r...
42
43
44
45
  
      return reqid, uid
  
  
be52af70   tangwang   first commit
46
  @router.post("/", response_model=SearchResponse)
16c42787   tangwang   feat: implement r...
47
  async def search(request: SearchRequest, http_request: Request):
be52af70   tangwang   first commit
48
      """
1f6d15fa   tangwang   重构:SPU级别索引、统一索引架构...
49
      Execute text search query (外部友好格式).
be52af70   tangwang   first commit
50
51
52
  
      Supports:
      - Multi-language query processing
bd96cead   tangwang   1. 动态多语言字段与统一策略配置
53
      - Unified text retrieval strategy (no boolean AST parsing)
be52af70   tangwang   first commit
54
55
      - Semantic search with embeddings
      - Custom ranking functions
6aa246be   tangwang   问题:Pydantic 应该能自动...
56
57
      - Exact match filters and range filters
      - Faceted search
1f6d15fa   tangwang   重构:SPU级别索引、统一索引架构...
58
59
      
      Requires tenant_id in header (X-Tenant-ID) or query parameter (tenant_id).
be52af70   tangwang   first commit
60
      """
16c42787   tangwang   feat: implement r...
61
      reqid, uid = extract_request_info(http_request)
4650fcec   tangwang   日志优化、日志串联(uid rqid)
62
63
      http_request.state.reqid = reqid
      http_request.state.uid = uid
16c42787   tangwang   feat: implement r...
64
  
1f6d15fa   tangwang   重构:SPU级别索引、统一索引架构...
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
      # Extract tenant_id (required)
      tenant_id = http_request.headers.get('X-Tenant-ID')
      if not tenant_id:
          # Try to get from query string
          from urllib.parse import parse_qs
          query_string = http_request.url.query
          if query_string:
              params = parse_qs(query_string)
              tenant_id = params.get('tenant_id', [None])[0]
      
      if not tenant_id:
          raise HTTPException(
              status_code=400,
              detail="tenant_id is required. Provide it via header 'X-Tenant-ID' or query parameter 'tenant_id'"
          )
  
16c42787   tangwang   feat: implement r...
81
82
83
84
85
      # Create request context
      context = create_request_context(reqid=reqid, uid=uid)
  
      # Set context in thread-local storage
      set_current_request_context(context)
be52af70   tangwang   first commit
86
87
  
      try:
99bea633   tangwang   add logs
88
89
90
          # Log request start (English logs, with key search parameters)
          client_ip = http_request.client.host if http_request.client else "unknown"
          user_agent = http_request.headers.get("User-Agent", "unknown")[:200]
16c42787   tangwang   feat: implement r...
91
          context.logger.info(
99bea633   tangwang   add logs
92
93
94
95
96
97
98
99
100
101
              "Received search request | "
              f"Tenant: {tenant_id} | "
              f"Query: {request.query} | "
              f"IP: {client_ip} | "
              f"User agent: {user_agent} | "
              f"size: {request.size} | from: {request.from_} | "
              f"sort_by: {request.sort_by} | sort_order: {request.sort_order} | "
              f"min_score: {request.min_score} | "
              f"language: {request.language} | "
              f"debug: {request.debug} | "
ff32d894   tangwang   rerank
102
103
104
              f"enable_rerank: {request.enable_rerank} | "
              f"rerank_query_template: {request.rerank_query_template} | "
              f"rerank_doc_template: {request.rerank_doc_template} | "
99bea633   tangwang   add logs
105
106
107
108
              f"sku_filter_dimension: {request.sku_filter_dimension} | "
              f"filters: {request.filters} | "
              f"range_filters: {request.range_filters} | "
              f"facets: {request.facets}",
16c42787   tangwang   feat: implement r...
109
110
111
              extra={'reqid': context.reqid, 'uid': context.uid}
          )
  
be52af70   tangwang   first commit
112
          # Get searcher from app state
bb3c5ef8   tangwang   灌入数据流程跑通
113
          from api.app import get_searcher
be52af70   tangwang   first commit
114
115
          searcher = get_searcher()
  
16c42787   tangwang   feat: implement r...
116
          # Execute search with context (using backend defaults from config)
be52af70   tangwang   first commit
117
118
          result = searcher.search(
              query=request.query,
1f6d15fa   tangwang   重构:SPU级别索引、统一索引架构...
119
              tenant_id=tenant_id,
be52af70   tangwang   first commit
120
121
122
              size=request.size,
              from_=request.from_,
              filters=request.filters,
6aa246be   tangwang   问题:Pydantic 应该能自动...
123
124
              range_filters=request.range_filters,
              facets=request.facets,
16c42787   tangwang   feat: implement r...
125
              min_score=request.min_score,
c86c8237   tangwang   支持聚合。过滤项补充了逻辑,但是有问题
126
              context=context,
c86c8237   tangwang   支持聚合。过滤项补充了逻辑,但是有问题
127
              sort_by=request.sort_by,
1f071951   tangwang   补充调试信息,记录包括各个阶段的 ...
128
              sort_order=request.sort_order,
577ec972   tangwang   返回给前端的字段、格式适配。主要包...
129
130
              debug=request.debug,
              language=request.language,
ca91352a   tangwang   更新文档
131
              sku_filter_dimension=request.sku_filter_dimension,
ff32d894   tangwang   rerank
132
133
134
              enable_rerank=request.enable_rerank,
              rerank_query_template=request.rerank_query_template,
              rerank_doc_template=request.rerank_doc_template,
be52af70   tangwang   first commit
135
136
          )
  
16c42787   tangwang   feat: implement r...
137
138
          # Include performance summary in response
          performance_summary = context.get_summary() if context else None
5f7d7f09   tangwang   性能测试报告.md
139
140
141
142
143
144
145
146
147
148
          stage_timings = {
              k: round(v, 2) for k, v in context.performance_metrics.stage_timings.items()
          }
          total_ms = round(float(context.performance_metrics.total_duration or result.took_ms), 2)
          context.logger.info(
              "Before response | total_ms: %s | stage_timings_ms: %s",
              total_ms,
              stage_timings,
              extra={'reqid': context.reqid, 'uid': context.uid}
          )
16c42787   tangwang   feat: implement r...
149
  
be52af70   tangwang   first commit
150
          # Convert to response model
3cd09b3b   tangwang   翻译接口改为调用qwen-mt-f...
151
          response = SearchResponse(
1f6d15fa   tangwang   重构:SPU级别索引、统一索引架构...
152
              results=result.results,
be52af70   tangwang   first commit
153
154
155
              total=result.total,
              max_score=result.max_score,
              took_ms=result.took_ms,
6aa246be   tangwang   问题:Pydantic 应该能自动...
156
              facets=result.facets,
16c42787   tangwang   feat: implement r...
157
              query_info=result.query_info,
1f6d15fa   tangwang   重构:SPU级别索引、统一索引架构...
158
159
              suggestions=result.suggestions,
              related_searches=result.related_searches,
1f071951   tangwang   补充调试信息,记录包括各个阶段的 ...
160
161
              performance_info=performance_summary,
              debug_info=result.debug_info
be52af70   tangwang   first commit
162
163
          )
  
28e57bb1   tangwang   日志体系优化
164
165
166
167
168
          response_payload = response.model_dump(mode="json")
          response_json = json.dumps(response_payload, ensure_ascii=False, separators=(",", ":"))
          response_digest = hashlib.sha256(response_json.encode("utf-8")).hexdigest()[:16]
          max_score = float(response.max_score or 0.0)
  
3cd09b3b   tangwang   翻译接口改为调用qwen-mt-f...
169
          context.logger.info(
28e57bb1   tangwang   日志体系优化
170
171
172
173
174
175
              "Search response | Total results: %s | Max score: %.4f | Time: %sms | payload_size: %s chars | digest: %s",
              response.total,
              max_score,
              response.took_ms,
              len(response_json),
              response_digest,
3cd09b3b   tangwang   翻译接口改为调用qwen-mt-f...
176
177
              extra={'reqid': context.reqid, 'uid': context.uid}
          )
28e57bb1   tangwang   日志体系优化
178
179
180
181
182
183
184
185
186
187
188
189
          _log_backend_verbose({
              "event": "search_response",
              "reqid": context.reqid,
              "uid": context.uid,
              "tenant_id": tenant_id,
              "total_results": response.total,
              "max_score": max_score,
              "took_ms": response.took_ms,
              "payload_size_chars": len(response_json),
              "sha256_16": response_digest,
              "response": response_payload,
          })
3cd09b3b   tangwang   翻译接口改为调用qwen-mt-f...
190
191
192
  
          return response
  
be52af70   tangwang   first commit
193
      except Exception as e:
16c42787   tangwang   feat: implement r...
194
195
196
197
          # Log error in context
          if context:
              context.set_error(e)
              context.logger.error(
99bea633   tangwang   add logs
198
                  f"Search request failed | error: {str(e)}",
16c42787   tangwang   feat: implement r...
199
200
                  extra={'reqid': context.reqid, 'uid': context.uid}
              )
be52af70   tangwang   first commit
201
          raise HTTPException(status_code=500, detail=str(e))
16c42787   tangwang   feat: implement r...
202
203
204
      finally:
          # Clear thread-local context
          clear_current_request_context()
be52af70   tangwang   first commit
205
206
207
  
  
  @router.post("/image", response_model=SearchResponse)
16c42787   tangwang   feat: implement r...
208
  async def search_by_image(request: ImageSearchRequest, http_request: Request):
be52af70   tangwang   first commit
209
      """
1f6d15fa   tangwang   重构:SPU级别索引、统一索引架构...
210
      Search by image similarity (外部友好格式).
be52af70   tangwang   first commit
211
212
  
      Uses image embeddings to find visually similar products.
6aa246be   tangwang   问题:Pydantic 应该能自动...
213
      Supports exact match filters and range filters.
1f6d15fa   tangwang   重构:SPU级别索引、统一索引架构...
214
215
      
      Requires tenant_id in header (X-Tenant-ID) or query parameter (tenant_id).
be52af70   tangwang   first commit
216
      """
16c42787   tangwang   feat: implement r...
217
      reqid, uid = extract_request_info(http_request)
4650fcec   tangwang   日志优化、日志串联(uid rqid)
218
219
      http_request.state.reqid = reqid
      http_request.state.uid = uid
16c42787   tangwang   feat: implement r...
220
  
1f6d15fa   tangwang   重构:SPU级别索引、统一索引架构...
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
      # Extract tenant_id (required)
      tenant_id = http_request.headers.get('X-Tenant-ID')
      if not tenant_id:
          from urllib.parse import parse_qs
          query_string = http_request.url.query
          if query_string:
              params = parse_qs(query_string)
              tenant_id = params.get('tenant_id', [None])[0]
      
      if not tenant_id:
          raise HTTPException(
              status_code=400,
              detail="tenant_id is required. Provide it via header 'X-Tenant-ID' or query parameter 'tenant_id'"
          )
  
16c42787   tangwang   feat: implement r...
236
237
238
239
240
241
      # Create request context
      context = create_request_context(reqid=reqid, uid=uid)
  
      # Set context in thread-local storage
      set_current_request_context(context)
  
be52af70   tangwang   first commit
242
      try:
99bea633   tangwang   add logs
243
244
          # Log request start for image search (English)
          client_ip = http_request.client.host if http_request.client else "unknown"
16c42787   tangwang   feat: implement r...
245
          context.logger.info(
99bea633   tangwang   add logs
246
247
248
249
              "Received image search request | "
              f"Tenant: {tenant_id} | "
              f"Image URL: {request.image_url} | "
              f"IP: {client_ip}",
16c42787   tangwang   feat: implement r...
250
251
252
              extra={'reqid': context.reqid, 'uid': context.uid}
          )
  
bb3c5ef8   tangwang   灌入数据流程跑通
253
          from api.app import get_searcher
be52af70   tangwang   first commit
254
255
256
257
258
          searcher = get_searcher()
  
          # Execute image search
          result = searcher.search_by_image(
              image_url=request.image_url,
1f6d15fa   tangwang   重构:SPU级别索引、统一索引架构...
259
              tenant_id=tenant_id,
be52af70   tangwang   first commit
260
              size=request.size,
6aa246be   tangwang   问题:Pydantic 应该能自动...
261
262
              filters=request.filters,
              range_filters=request.range_filters
be52af70   tangwang   first commit
263
264
          )
  
16c42787   tangwang   feat: implement r...
265
266
267
          # Include performance summary in response
          performance_summary = context.get_summary() if context else None
  
3cd09b3b   tangwang   翻译接口改为调用qwen-mt-f...
268
          response = SearchResponse(
1f6d15fa   tangwang   重构:SPU级别索引、统一索引架构...
269
              results=result.results,
be52af70   tangwang   first commit
270
271
272
              total=result.total,
              max_score=result.max_score,
              took_ms=result.took_ms,
6aa246be   tangwang   问题:Pydantic 应该能自动...
273
              facets=result.facets,
16c42787   tangwang   feat: implement r...
274
              query_info=result.query_info,
1f6d15fa   tangwang   重构:SPU级别索引、统一索引架构...
275
276
              suggestions=result.suggestions,
              related_searches=result.related_searches,
16c42787   tangwang   feat: implement r...
277
              performance_info=performance_summary
be52af70   tangwang   first commit
278
279
          )
  
28e57bb1   tangwang   日志体系优化
280
281
282
283
284
          response_payload = response.model_dump(mode="json")
          response_json = json.dumps(response_payload, ensure_ascii=False, separators=(",", ":"))
          response_digest = hashlib.sha256(response_json.encode("utf-8")).hexdigest()[:16]
          max_score = float(response.max_score or 0.0)
  
3cd09b3b   tangwang   翻译接口改为调用qwen-mt-f...
285
          context.logger.info(
28e57bb1   tangwang   日志体系优化
286
287
288
289
290
291
              "Image search response | Total results: %s | Max score: %.4f | Time: %sms | payload_size: %s chars | digest: %s",
              response.total,
              max_score,
              response.took_ms,
              len(response_json),
              response_digest,
3cd09b3b   tangwang   翻译接口改为调用qwen-mt-f...
292
293
              extra={'reqid': context.reqid, 'uid': context.uid}
          )
28e57bb1   tangwang   日志体系优化
294
295
296
297
298
299
300
301
302
303
304
305
          _log_backend_verbose({
              "event": "image_search_response",
              "reqid": context.reqid,
              "uid": context.uid,
              "tenant_id": tenant_id,
              "total_results": response.total,
              "max_score": max_score,
              "took_ms": response.took_ms,
              "payload_size_chars": len(response_json),
              "sha256_16": response_digest,
              "response": response_payload,
          })
3cd09b3b   tangwang   翻译接口改为调用qwen-mt-f...
306
307
308
  
          return response
  
be52af70   tangwang   first commit
309
      except ValueError as e:
16c42787   tangwang   feat: implement r...
310
311
312
          if context:
              context.set_error(e)
              context.logger.error(
99bea633   tangwang   add logs
313
                  f"Image search request parameter error | error: {str(e)}",
16c42787   tangwang   feat: implement r...
314
315
                  extra={'reqid': context.reqid, 'uid': context.uid}
              )
be52af70   tangwang   first commit
316
317
          raise HTTPException(status_code=400, detail=str(e))
      except Exception as e:
16c42787   tangwang   feat: implement r...
318
319
320
          if context:
              context.set_error(e)
              context.logger.error(
99bea633   tangwang   add logs
321
                  f"Image search request failed | error: {str(e)}",
16c42787   tangwang   feat: implement r...
322
323
                  extra={'reqid': context.reqid, 'uid': context.uid}
              )
be52af70   tangwang   first commit
324
          raise HTTPException(status_code=500, detail=str(e))
16c42787   tangwang   feat: implement r...
325
326
327
      finally:
          # Clear thread-local context
          clear_current_request_context()
be52af70   tangwang   first commit
328
329
  
  
6aa246be   tangwang   问题:Pydantic 应该能自动...
330
331
332
  @router.get("/suggestions", response_model=SearchSuggestResponse)
  async def search_suggestions(
      q: str = Query(..., min_length=1, description="搜索查询"),
ff9efda0   tangwang   suggest
333
      size: int = Query(10, ge=1, le=50, description="建议数量(1-50)"),
ded6f29e   tangwang   补充suggestion模块
334
      language: str = Query("en", description="请求语言,如 zh/en/ar/ru"),
ded6f29e   tangwang   补充suggestion模块
335
336
      debug: bool = Query(False, description="是否返回调试信息"),
      http_request: Request = None,
6aa246be   tangwang   问题:Pydantic 应该能自动...
337
338
339
340
  ):
      """
      获取搜索建议(自动补全)。
      
ff9efda0   tangwang   suggest
341
      获取搜索建议(自动补全,支持多语言)。
6aa246be   tangwang   问题:Pydantic 应该能自动...
342
      """
ded6f29e   tangwang   补充suggestion模块
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
      # Extract tenant_id (required)
      tenant_id = http_request.headers.get("X-Tenant-ID") if http_request else None
      if not tenant_id and http_request:
          from urllib.parse import parse_qs
          query_string = http_request.url.query
          if query_string:
              params = parse_qs(query_string)
              tenant_id = params.get("tenant_id", [None])[0]
  
      if not tenant_id:
          raise HTTPException(
              status_code=400,
              detail="tenant_id is required. Provide it via header 'X-Tenant-ID' or query parameter 'tenant_id'",
          )
  
      try:
          from api.app import get_suggestion_service
  
          service = get_suggestion_service()
          result = service.search(
              tenant_id=tenant_id,
              query=q,
              language=language,
              size=size,
ded6f29e   tangwang   补充suggestion模块
367
368
369
370
371
372
373
374
375
376
377
378
379
380
          )
          response = SearchSuggestResponse(
              query=result["query"],
              language=result.get("language"),
              resolved_language=result.get("resolved_language"),
              suggestions=result["suggestions"],
              took_ms=result["took_ms"],
          )
          if debug:
              # keep response_model stable; debug info stays inside suggestions payload for now
              return response
          return response
      except Exception as e:
          raise HTTPException(status_code=500, detail=str(e))
6aa246be   tangwang   问题:Pydantic 应该能自动...
381
382
383
384
385
  
  
  @router.get("/instant", response_model=SearchResponse)
  async def instant_search(
      q: str = Query(..., min_length=2, description="搜索查询"),
1f6d15fa   tangwang   重构:SPU级别索引、统一索引架构...
386
      size: int = Query(5, ge=1, le=20, description="结果数量"),
6aa246be   tangwang   问题:Pydantic 应该能自动...
387
388
389
390
391
392
393
394
  ):
      """
      即时搜索(Instant Search)。
      
      功能说明:
      - 边输入边搜索,无需点击搜索按钮
      - 返回简化的搜索结果
      
26b910bd   tangwang   refactor service ...
395
      注意:此功能暂未开放,当前明确返回 501
6aa246be   tangwang   问题:Pydantic 应该能自动...
396
      """
26b910bd   tangwang   refactor service ...
397
398
399
400
401
402
403
      # 明确暴露当前接口尚未完成实现,避免调用不完整逻辑导致隐式运行时错误。
      raise HTTPException(
          status_code=501,
          detail=(
              "/search/instant is not implemented yet. "
              "Use POST /search/ for production traffic."
          ),
6aa246be   tangwang   问题:Pydantic 应该能自动...
404
405
406
      )
  
  
be52af70   tangwang   first commit
407
  @router.get("/{doc_id}", response_model=DocumentResponse)
e4a39cc8   tangwang   索引隔离。 不同的tenant_i...
408
  async def get_document(doc_id: str, http_request: Request):
be52af70   tangwang   first commit
409
410
      """
      Get a single document by ID.
e4a39cc8   tangwang   索引隔离。 不同的tenant_i...
411
412
      
      Requires tenant_id in header (X-Tenant-ID) or query parameter (tenant_id).
be52af70   tangwang   first commit
413
414
      """
      try:
e4a39cc8   tangwang   索引隔离。 不同的tenant_i...
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
          # Extract tenant_id (required)
          tenant_id = http_request.headers.get('X-Tenant-ID')
          if not tenant_id:
              # Try to get from query string
              from urllib.parse import parse_qs
              query_string = http_request.url.query
              if query_string:
                  params = parse_qs(query_string)
                  tenant_id = params.get('tenant_id', [None])[0]
          
          if not tenant_id:
              raise HTTPException(
                  status_code=400,
                  detail="tenant_id is required. Provide it via header 'X-Tenant-ID' or query parameter 'tenant_id'"
              )
          
bb3c5ef8   tangwang   灌入数据流程跑通
431
          from api.app import get_searcher
be52af70   tangwang   first commit
432
433
          searcher = get_searcher()
  
e4a39cc8   tangwang   索引隔离。 不同的tenant_i...
434
          doc = searcher.get_document(tenant_id=tenant_id, doc_id=doc_id)
be52af70   tangwang   first commit
435
436
  
          if doc is None:
e4a39cc8   tangwang   索引隔离。 不同的tenant_i...
437
              raise HTTPException(status_code=404, detail=f"Document {doc_id} not found for tenant {tenant_id}")
be52af70   tangwang   first commit
438
439
440
441
442
443
444
  
          return DocumentResponse(id=doc_id, source=doc)
  
      except HTTPException:
          raise
      except Exception as e:
          raise HTTPException(status_code=500, detail=str(e))
985752f5   tangwang   1. 前端调试功能
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
471
472
473
474
475
476
477
478
  
  
  @router.get("/es-doc/{spu_id}")
  async def get_es_raw_document(spu_id: str, http_request: Request):
      """
      Get raw Elasticsearch document(s) for a given SPU ID.
  
      This is intended for debugging in the test frontend:
      it queries the tenant-specific ES index with a term filter on spu_id
      and returns the raw ES search response.
      """
      # Extract tenant_id (required)
      tenant_id = http_request.headers.get("X-Tenant-ID")
      if not tenant_id:
          from urllib.parse import parse_qs
          query_string = http_request.url.query
          if query_string:
              params = parse_qs(query_string)
              tenant_id = params.get("tenant_id", [None])[0]
  
      if not tenant_id:
          raise HTTPException(
              status_code=400,
              detail="tenant_id is required. Provide it via header 'X-Tenant-ID' or query parameter 'tenant_id'",
          )
  
      try:
          from api.app import get_searcher
  
          searcher = get_searcher()
          es_client = searcher.es_client
          index_name = get_tenant_index_name(tenant_id)
  
          body = {
985752f5   tangwang   1. 前端调试功能
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
              "query": {
                  "bool": {
                      "filter": [
                          {
                              "term": {
                                  "spu_id": spu_id,
                              }
                          }
                      ]
                  }
              },
          }
  
          es_response = es_client.search(index_name=index_name, body=body, size=5, from_=0)
          return es_response
      except HTTPException:
          raise
      except Exception as e:
          raise HTTPException(status_code=500, detail=str(e))