返回

通智搜尋 API 介面說明書

通智雲團隊 ·
API整合 搜尋系統 通智搜尋
通智搜尋 API 介面說明書

通智搜尋是一項高效能智能搜尋服務,提供全文檢索、智能聚合與靈活過濾等功能,協助你快速建構專業搜尋體驗。

目錄


快速開始

基本資訊

項目 說明
介面地址 https://api.tengence.com/v1/search
請求方式 POST
內容類型 application/json
字元編碼 UTF-8

快速範例

curl -X POST "https://api.tengence.com/v1/search" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer {YOUR_API_KEY}" \
  -d '{
    "query": "ai",
    "page": 1,
    "size": 10
  }'

認證方式

所有介面均需要在請求標頭中包含 API Key:

Authorization: Bearer {YOUR_API_KEY}

獲取 API Key:登入通智控制台(https://console.tengence.com),於「應用詳情」頁面中獲取 API Key。

{
  "code": "SUCCESS",
  "message": "Operation successful",
  "data": {
    "items": [
      {
        "id": "123",
        "title": "AI Agent Platform",
        "price": 4999
      }
    ],
    "total": 1520,
    "aggs": [],
    "took": 45
  },
  "success": true
}

搜尋介面

POST https://api.tengence.com/v1/search

請求方式:POST

執行搜尋請求並回傳符合結果。

請求標頭

參數名 類型 必填 說明
Authorization string 是 Bearer {YOUR_API_KEY}
Content-Type string 是 application/json

請求參數

參數名 類型 必填 預設值 說明
query string 是 – 搜尋關鍵字
page number 否 1 頁碼,由 1 開始
size number 否 20 每頁數量,最大 100
sortFields array 否 – 排序欄位清單
highlightFields array 否 – 高亮欄位清單
aggregations array 否 – 聚合設定清單
searchFields array 否 – 搜尋欄位限制
includeFields array 否 – 傳回欄位限制
filters array 否 – 過濾條件清單

filters 參數結構

filters 參數用於精確過濾搜尋結果,支援多種運算子。

FilterParam 結構

欄位名 類型 必填 說明
field string 是 欄位名稱,使用底線命名法(snake_case),例如 create_time
operator string 是 運算子,詳見下方支援的運算子清單
value string/number 否 單一數值,用於 eq/ne/gt/gte/lt/lte 運算子
values array 否 多值陣列,用於 in/not_in 運算子

支援的運算子

運算子 含義 適用類型 示例值
eq 等於 字串/數字/日期 "published"
ne 不等於 字串/數字/日期 "draft"
gt 大於 數字/日期 100
gte 大於或等於 數字/日期 100
lt 小於 數字/日期 1000
lte 小於或等於 數字/日期 1000
in 包含於 字串/數字 ["a", "b"]
not_in 不包含於 字串/數字 ["x", "y"]
exists 欄位存在 – null
not_exists 欄位不存在 – null

說明

sortFields 參數結構

欄位名 類型 必填 說明
field string 是 排序欄位
order string 否 ASC/DESC,預設 DESC

aggregations 參數結構

欄位名 類型 必填 說明
name string 是 聚合名稱(傳回結果的 key)
field string 是 聚合欄位
type string 是 聚合類型:terms/range/date_histogram
size number 否 傳回數量(僅 terms,預設 10)
sortBy string 否 排序欄位:count/value(僅 terms)
sortOrder string 否 排序順序:ASC/DESC(僅 terms)
ranges array 否 範圍定義(僅 range)
interval string 否 時間間隔(僅 date_histogram)

interval 參數說明

值 說明 適用場景
1m 按分鐘統計 即時數據監控
1h 按小時統計 日趨勢分析
1d 按天統計 日報表
1w 按週統計 週報表
1M 按月統計 月報表
1y 按年統計 年度報表

回應結構

欄位名 類型 說明
code string 狀態碼
message string 回應訊息
data object 回應資料
data.items array 搜尋結果清單
data.total number 符合文件總數
data.aggs array 聚合結果清單
data.took number 查詢耗時(毫秒)
success boolean 是否成功

回應範例

curl -X POST "https://api.tengence.com/v1/search" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer {YOUR_API_KEY}" \
  -d '{
    "query": "ai"
  }'

1. 基礎搜尋

場景:最簡單的關鍵字搜尋“`
// JavaScript
const response = await fetch('https://api.tengence.com/v1/search', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer {YOUR_API_KEY}'
},
body: JSON.stringify({
query: 'ai'
})
});
const data = await response.json();

Python

import requests

response = requests.post(
'https://api.tengence.com/v1/search',
headers={
'Content-Type': 'application/json',
'Authorization': 'Bearer {YOUR_API_KEY}'
},
json={
'query': 'ai'
}
)
data = response.json()

// Java
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.tengence.com/v1/search"))
.header("Content-Type", "application/json")
.header("Authorization", "Bearer {YOUR_API_KEY}")
.POST(HttpRequest.BodyPublishers.ofString(
"{"query": "ai"}"
))
.build();

HttpResponse response = client.send(request,
HttpResponse.BodyHandlers.ofString());

// PHP
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tengence.com/v1/search");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Authorization: Bearer {YOUR_API_KEY}'
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
'query' => 'ai'
]));
$response = curl_exec($ch);
curl_close($ch);

// Go
package main

import (
"bytes"
"encoding/json"
"net/http"
)

func main() {
data := map[string]string{"query": "ai"}
jsonData, _ := json.Marshal(data)

req, _ := http.NewRequest("POST",
    "https://api.tengence.com/v1/search",
    bytes.NewBuffer(jsonData))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer {YOUR_API_KEY}")

client := &http.Client{}
client.Do(req)

}


### 2. 分頁搜尋

**場景**:取得第 2 頁結果,每頁 20 筆```
curl -X POST "https://api.tengence.com/v1/search" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer {YOUR_API_KEY}" \
  -d '{
    "query": "ai",
    "page": 2,
    "size": 20
  }'
// JavaScript
const response = await fetch('https://api.tengence.com/v1/search', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer {YOUR_API_KEY}'
  },
  body: JSON.stringify({
    query: 'ai',
    page: 2,
    size: 20
  })
});
# Python
response = requests.post(
    'https://api.tengence.com/v1/search',
    headers={
        'Content-Type': 'application/json',
        'Authorization': 'Bearer {YOUR_API_KEY}'
    },
    json={
        'query': 'ai',
        'page': 2,
        'size': 20
    }
)

3. 排序 – 价格降序

场景:按价格从高到低排序

curl -X POST "https://api.tengence.com/v1/search" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer {YOUR_API_KEY}" \
  -d '{
    "query": "ai",
    "sortFields": [{"field": "price", "order": "DESC"}]
  }'

3. 排序 – 價格由高至低

場景:按價格由高到低排序“`
// JavaScript
const response = await fetch('https://api.tengence.com/v1/search', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer {YOUR_API_KEY}'
},
body: JSON.stringify({
query: 'ai',
sortFields: [{ field: 'price', order: 'DESC' }]
})
});

Python

response = requests.post(
'https://api.tengence.com/v1/search',
headers={
'Content-Type': 'application/json',
'Authorization': 'Bearer {YOUR_API_KEY}'
},
json={
'query': 'ai',
'sortFields': [{'field': 'price', 'order': 'DESC'}]
}
)


---

### 4\. 多字段排序

**场景**:先按评分降序,再按评论数降序

curl -X POST "https://api.tengence.com/v1/search"
-H "Content-Type: application/json"
-H "Authorization: Bearer {YOUR_API_KEY}"
-d '{
"query": "ai",
"sortFields": [
{"field": "rating", "order": "DESC"},
{"field": "review_count", "order": "DESC"}
]
}'


### 4. 多欄位排序

**場景**:先按評分由高至低,再按評論數由高至低```
// JavaScript
const response = await fetch('https://api.tengence.com/v1/search', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer {YOUR_API_KEY}'
  },
  body: JSON.stringify({
    query: 'ai',
    sortFields: [
      { field: 'rating', order: 'DESC' },
      { field: 'review_count', order: 'DESC' }
    ]
  })
});
# Python
response = requests.post(
    'https://api.tengence.com/v1/search',
    headers={
        'Content-Type': 'application/json',
        'Authorization': 'Bearer {YOUR_API_KEY}'
    },
    json={
        'query': 'ai',
        'sortFields': [
            {'field': 'rating', 'order': 'DESC'},
            {'field': 'review_count', 'order': 'DESC'}
        ]
    }
)

5. 聚合 – 分类统计

场景:统计各分类下的内容数量

curl -X POST "https://api.tengence.com/v1/search" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer {YOUR_API_KEY}" \
  -d '{
    "query": "ai",
    "aggregations": [{
      "name": "by_category",
      "field": "category",
      "type": "terms",
      "size": 20,
      "sortBy": "count",
      "sortOrder": "DESC"
    }]
  }'

5. 聚合 – 分類統計

場景:統計各分類下的內容數量“`
// JavaScript
const response = await fetch('https://api.tengence.com/v1/search', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer {YOUR_API_KEY}'
},
body: JSON.stringify({
query: 'ai',
aggregations: [{
name: 'by_category',
field: 'category',
type: 'terms',
size: 20,
sortBy: 'count',
sortOrder: 'DESC'
}]
})
});

Python

response = requests.post(
'https://api.tengence.com/v1/search',
headers={
'Content-Type': 'application/json',
'Authorization': 'Bearer {YOUR_API_KEY}'
},
json={
'query': 'ai',
'aggregations': [{
'name': 'by_category',
'field': 'category',
'type': 'terms',
'size': 20,
'sortBy': 'count',
'sortOrder': 'DESC'
}]
}
)


---

### 6\. 聚合 – 价格区间统计

**场景**:统计不同价格区间的商品分布

curl -X POST "https://api.tengence.com/v1/search"
-H "Content-Type: application/json"
-H "Authorization: Bearer {YOUR_API_KEY}"
-d '{
"query": "ai",
"aggregations": [{
"name": "by_price_range",
"field": "price",
"type": "range",
"ranges": [
{"key": "low", "from": 0, "to": 100},
{"key": "medium", "from": 100, "to": 500},
{"key": "high", "from": 500, "to": 1000},
{"key": "luxury", "from": 1000}
]
}]
}'


### 6. 聚合 – 價格區間統計

**場景**:統計不同價格區間的商品分佈```
// JavaScript
const response = await fetch('https://api.tengence.com/v1/search', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer {YOUR_API_KEY}'
  },
  body: JSON.stringify({
    query: 'ai',
    aggregations: [{
      name: 'by_price_range',
      field: 'price',
      type: 'range',
      ranges: [
        { key: 'low', from: 0, to: 100 },
        { key: 'medium', from: 100, to: 500 },
        { key: 'high', from: 500, to: 1000 },
        { key: 'luxury', from: 1000 }
      ]
    }]
  })
});
# Python
response = requests.post(
    'https://api.tengence.com/v1/search',
    headers={
        'Content-Type': 'application/json',
        'Authorization': 'Bearer {YOUR_API_KEY}'
    },
    json={
        'query': 'ai',
        'aggregations': [{
            'name': 'by_price_range',
            'field': 'price',
            'type': 'range',
            'ranges': [
                {'key': 'low', 'from': 0, 'to': 100},
                {'key': 'medium', 'from': 100, 'to': 500},
                {'key': 'high', 'from': 500, 'to': 1000},
                {'key': 'luxury', 'from': 1000}
            ]
        }]
    }
)

7. 聚合 – 日期趋势(按天)

场景:查看最近30天的每日数量趋势

curl -X POST "https://api.tengence.com/v1/search" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer {YOUR_API_KEY}" \
  -d '{
    "query": "ai",
    "aggregations": [{
      "name": "daily_trend",
      "field": "create_time",
      "type": "date_histogram",
      "interval": "1d"
    }],
    "size": 0
  }'

7. 聚合 – 日期趨勢(按天)

場景:查看最近 30 天的每日數量趨勢“`
// JavaScript
const response = await fetch('https://api.tengence.com/v1/search', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer {YOUR_API_KEY}'
},
body: JSON.stringify({
query: 'ai',
aggregations: [{
name: 'daily_trend',
field: 'create_time',
type: 'date_histogram',
interval: '1d'
}],
size: 0
})
});

Python

response = requests.post(
'https://api.tengence.com/v1/search',
headers={
'Content-Type': 'application/json',
'Authorization': 'Bearer {YOUR_API_KEY}'
},
json={
'query': 'ai',
'aggregations': [{
'name': 'daily_trend',
'field': 'create_time',
'type': 'date_histogram',
'interval': '1d'
}],
'size': 0
}
)


---

### 8\. 聚合 – 月份趋势

**场景**:按月统计(12个月趋势)

curl -X POST "https://api.tengence.com/v1/search"
-H "Content-Type: application/json"
-H "Authorization: Bearer {YOUR_API_KEY}"
-d '{
"query": "ai",
"aggregations": [{
"name": "monthly_trend",
"field": "create_time",
"type": "date_histogram",
"interval": "1M"
}]
}'


### 8. 聚合 – 月份趨勢

**場景**:按月統計(12 個月趨勢)```
// JavaScript
const response = await fetch('https://api.tengence.com/v1/search', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer {YOUR_API_KEY}'
  },
  body: JSON.stringify({
    query: 'ai',
    aggregations: [{
      name: 'monthly_trend',
      field: 'create_time',
      type: 'date_histogram',
      interval: '1M'
    }]
  })
});
# Python
response = requests.post(
    'https://api.tengence.com/v1/search',
    headers={
        'Content-Type': 'application/json',
        'Authorization': 'Bearer {YOUR_API_KEY}'
    },
    json={
        'query': 'ai',
        'aggregations': [{
            'name': 'monthly_trend',
            'field': 'create_time',
            'type': 'date_histogram',
            'interval': '1M'
        }]
    }
)

9. 多聚合组合 – 分类+品牌+价格

场景:搜索时,同时展示分类、品牌、价格区间筛选

curl -X POST "https://api.tengence.com/v1/search" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer {YOUR_API_KEY}" \
  -d '{
    "query": "ai",
    "page": 1,
    "size": 20,
    "aggregations": [
      {
        "name": "by_category",
        "field": "category",
        "type": "terms",
        "size": 10
      },
      {
        "name": "by_brand",
        "field": "brand",
        "type": "terms",
        "size": 10
      },
      {
        "name": "by_price_range",
        "field": "price",
        "type": "range",
        "ranges": [
          {"key": "under_1000", "to": 1000},
          {"key": "1000_3000", "from": 1000, "to": 3000},
          {"key": "3000_5000", "from": 3000, "to": 5000},
          {"key": "above_5000", "from": 5000}
        ]
      }
    ]
  }'

9. 多聚合組合 – 分類+品牌+價格

場景:搜尋時同時展示分類、品牌、價格區間篩選“`
// JavaScript
const response = await fetch('https://api.tengence.com/v1/search', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer {YOUR_API_KEY}'
},
body: JSON.stringify({
query: 'ai',
page: 1,
size: 20,
aggregations: [
{
name: 'by_category',
field: 'category',
type: 'terms',
size: 10
},
{
name: 'by_brand',
field: 'brand',
type: 'terms',
size: 10
},
{
name: 'by_price_range',
field: 'price',
type: 'range',
ranges: [
{ key: 'under_1000', to: 1000 },
{ key: '1000_3000', from: 1000, to: 3000 },
{ key: '3000_5000', from: 3000, to: 5000 },
{ key: 'above_5000', from: 5000 }
]
}
]
})
});

Python

response = requests.post(
'https://api.tengence.com/v1/search',
headers={
'Content-Type': 'application/json',
'Authorization': 'Bearer {YOUR_API_KEY}'
},
json={
'query': 'ai',
'page': 1,
'size': 20,
'aggregations': [
{
'name': 'by_category',
'field': 'category',
'type': 'terms',
'size': 10
},
{
'name': 'by_brand',
'field': 'brand',
'type': 'terms',
'size': 10
},
{
'name': 'by_price_range',
'field': 'price',
'type': 'range',
'ranges': [
{'key': 'under_1000', 'to': 1000},
{'key': '1000_3000', 'from': 1000, 'to': 3000},
{'key': '3000_5000', 'from': 3000, 'to': 5000},
{'key': 'above_5000', 'from': 5000}
]
}
]
}
)


---

### 10\. 过滤 – 精确匹配

**场景**:只显示已发布且属于特定分类的内容

curl -X POST "https://api.tengence.com/v1/search"
-H "Content-Type: application/json"
-H "Authorization: Bearer {YOUR_API_KEY}"
-d '{
"query": "ai",
"filters": [
{"field": "status", "operator": "eq", "value": "published"},
{"field": "category", "operator": "eq", "value": "技术"}
]
}'


### 10. 過濾 – 精確比對

**場景**:只顯示已發佈且屬於特定分類的內容```
// JavaScript
const response = await fetch('https://api.tengence.com/v1/search', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer {YOUR_API_KEY}'
  },
  body: JSON.stringify({
    query: 'ai',
    filters: [
      { field: 'status', operator: 'eq', value: 'published' },
      { field: 'category', operator: 'eq', value: '技术' }
    ]
  })
});
# Python
response = requests.post(
    'https://api.tengence.com/v1/search',
    headers={
        'Content-Type': 'application/json',
        'Authorization': 'Bearer {YOUR_API_KEY}'
    },
    json={
        'query': 'ai',
        'filters': [
            {'field': 'status', 'operator': 'eq', 'value': 'published'},
            {'field': 'category', 'operator': 'eq', 'value': '技术'}
        ]
    }
)

11. 过滤 – 价格范围

场景:搜索价格在 1000-5000 之间的商品

curl -X POST "https://api.tengence.com/v1/search" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer {YOUR_API_KEY}" \
  -d '{
    "query": "ai",
    "filters": [
      {"field": "price", "operator": "gte", "value": 1000},
      {"field": "price", "operator": "lte", "value": 5000}
    ]
  }'

11. 過濾 – 價格範圍

場景:搜尋價格介乎 1000 至 5000 之間的商品“`
// JavaScript
const response = await fetch('https://api.tengence.com/v1/search', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer {YOUR_API_KEY}'
},
body: JSON.stringify({
query: 'ai',
filters: [
{ field: 'price', operator: 'gte', value: 1000 },
{ field: 'price', operator: 'lte', value: 5000 }
]
})
});

Python

response = requests.post(
'https://api.tengence.com/v1/search',
headers={
'Content-Type': 'application/json',
'Authorization': 'Bearer {YOUR_API_KEY}'
},
json={
'query': 'ai',
'filters': [
{'field': 'price', 'operator': 'gte', 'value': 1000},
{'field': 'price', 'operator': 'lte', 'value': 5000}
]
}
)


---

### 12\. 过滤 – 日期范围

**场景**:只搜索 2025 年发布的内容

curl -X POST "https://api.tengence.com/v1/search"
-H "Content-Type: application/json"
-H "Authorization: Bearer {YOUR_API_KEY}"
-d '{
"query": "ai",
"filters": [
{"field": "create_time", "operator": "gte", "value": "2025-01-01"},
{"field": "create_time", "operator": "lte", "value": "2025-12-31"}
]
}'


### 12. 過濾 – 日期範圍

**場景**:只搜尋 2025 年發佈的內容```
// JavaScript
const response = await fetch('https://api.tengence.com/v1/search', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer {YOUR_API_KEY}'
  },
  body: JSON.stringify({
    query: 'ai',
    filters: [
      { field: 'create_time', operator: 'gte', value: '2025-01-01' },
      { field: 'create_time', operator: 'lte', value: '2025-12-31' }
    ]
  })
});
# Python
response = requests.post(
    'https://api.tengence.com/v1/search',
    headers={
        'Content-Type': 'application/json',
        'Authorization': 'Bearer {YOUR_API_KEY}'
    },
    json={
        'query': 'ai',
        'filters': [
            {'field': 'create_time', 'operator': 'gte', 'value': '2025-01-01'},
            {'field': 'create_time', 'operator': 'lte', 'value': '2025-12-31'}
        ]
    }
)

13. 过滤 – 多值匹配 (IN)

场景:搜索多个分类下的内容

curl -X POST "https://api.tengence.com/v1/search" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer {YOUR_API_KEY}" \
  -d '{
    "query": "ai",
    "filters": [
      {"field": "category", "operator": "in", "values": ["机器学习", "深度学习", "自然语言处理"]}
    ]
  }'

13. 過濾 – 多值比對 (IN)

場景:搜尋多個分類下的內容“`
// JavaScript
const response = await fetch('https://api.tengence.com/v1/search', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer {YOUR_API_KEY}'
},
body: JSON.stringify({
query: 'ai',
filters: [
{ field: 'category', operator: 'in', values: ['机器学习', '深度学习', '自然语言处理'] }
]
})
});

Python

response = requests.post(
'https://api.tengence.com/v1/search',
headers={
'Content-Type': 'application/json',
'Authorization': 'Bearer {YOUR_API_KEY}'
},
json={
'query': 'ai',
'filters': [
{'field': 'category', 'operator': 'in', 'values': ['机器学习', '深度学习', '自然语言处理']}
]
}
)


---

### 14\. 过滤 – 排除值 (NOT IN)

**场景**:排除特定标签的内容

curl -X POST "https://api.tengence.com/v1/search"
-H "Content-Type: application/json"
-H "Authorization: Bearer {YOUR_API_KEY}"
-d '{
"query": "ai",
"filters": [
{"field": "tags", "operator": "not_in", "values": ["广告", "推广"]}
]
}'


### 14. 過濾 – 排除數值 (NOT IN)

**場景**:排除特定標籤的內容```
// JavaScript
const response = await fetch('https://api.tengence.com/v1/search', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer {YOUR_API_KEY}'
  },
  body: JSON.stringify({
    query: 'ai',
    filters: [
      { field: 'tags', operator: 'not_in', values: ['广告', '推广'] }
    ]
  })
});
# Python
response = requests.post(
    'https://api.tengence.com/v1/search',
    headers={
        'Content-Type': 'application/json',
        'Authorization': 'Bearer {YOUR_API_KEY}'
    },
    json={
        'query': 'ai',
        'filters': [
            {'field': 'tags', 'operator': 'not_in', 'values': ['广告', '推广']}
        ]
    }
)

15. 过滤 – 大于/小于

场景:搜索评分大于 4.5 的内容

curl -X POST "https://api.tengence.com/v1/search" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer {YOUR_API_KEY}" \
  -d '{
    "query": "ai",
    "filters": [
      {"field": "rating", "operator": "gt", "value": 4.5}
    ]
  }'

15. 過濾 – 大於/小於

場景:搜尋評分大於 4.5 的內容“`
// JavaScript
const response = await fetch('https://api.tengence.com/v1/search', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer {YOUR_API_KEY}'
},
body: JSON.stringify({
query: 'ai',
filters: [
{ field: 'rating', operator: 'gt', value: 4.5 }
]
})
});

Python

response = requests.post(
'https://api.tengence.com/v1/search',
headers={
'Content-Type': 'application/json',
'Authorization': 'Bearer {YOUR_API_KEY}'
},
json={
'query': 'ai',
'filters': [
{'field': 'rating', 'operator': 'gt', 'value': 4.5}
]
}
)


---

### 16\. 综合过滤 – 电商商品筛选

**场景**:筛选商品,价格 2000-5000,品牌为指定值,状态为在售

curl -X POST "https://api.tengence.com/v1/search"
-H "Content-Type: application/json"
-H "Authorization: Bearer {YOUR_API_KEY}"
-d '{
"query": "ai",
"page": 1,
"size": 20,
"filters": [
{"field": "price", "operator": "gte", "value": 2000},
{"field": "price", "operator": "lte", "value": 5000},
{"field": "brand", "operator": "in", "values": ["Apple", "华为", "HUAWEI"]},
{"field": "status", "operator": "eq", "value": "on_sale"}
],
"sortFields": [{"field": "sales_count", "order": "DESC"}]
}'


### 16. 綜合過濾 – 電商商品篩選

**場景**:篩選商品,價格 2000–5000,品牌為指定值,狀態為在售```
// JavaScript
const response = await fetch('https://api.tengence.com/v1/search', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer {YOUR_API_KEY}'
  },
  body: JSON.stringify({
    query: 'ai',
    page: 1,
    size: 20,
    filters: [
      { field: 'price', operator: 'gte', value: 2000 },
      { field: 'price', operator: 'lte', value: 5000 },
      { field: 'brand', operator: 'in', values: ['Apple', '华为', 'HUAWEI'] },
      { field: 'status', operator: 'eq', value: 'on_sale' }
    ],
    sortFields: [{ field: 'sales_count', order: 'DESC' }]
  })
});
# Python
response = requests.post(
    'https://api.tengence.com/v1/search',
    headers={
        'Content-Type': 'application/json',
        'Authorization': 'Bearer {YOUR_API_KEY}'
    },
    json={
        'query': 'ai',
        'page': 1,
        'size': 20,
        'filters': [
            {'field': 'price', 'operator': 'gte', 'value': 2000},
            {'field': 'price', 'operator': 'lte', 'value': 5000},
            {'field': 'brand', 'operator': 'in', 'values': ['Apple', '华为', 'HUAWEI']},
            {'field': 'status', 'operator': 'eq', 'value': 'on_sale'}
        ],
        'sortFields': [{'field': 'sales_count', 'order': 'DESC'}]
    }
)

17. 高亮 – 指定高亮字段

场景:在标题和内容中高亮显示搜索词

curl -X POST "https://api.tengence.com/v1/search" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer {YOUR_API_KEY}" \
  -d '{
    "query": "ai",
    "highlightFields": ["title", "content"]
  }'

17. 高亮 – 指定高亮欄位

場景:在標題與內容中高亮顯示搜尋詞“`
// JavaScript
const response = await fetch('https://api.tengence.com/v1/search', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer {YOUR_API_KEY}'
},
body: JSON.stringify({
query: 'ai',
highlightFields: ['title', 'content']
})
});

Python

response = requests.post(
'https://api.tengence.com/v1/search',
headers={
'Content-Type': 'application/json',
'Authorization': 'Bearer {YOUR_API_KEY}'
},
json={
'query': 'ai',
'highlightFields': ['title', 'content']
}
)


---

### 18\. 字段选择 – 限制搜索字段

**场景**:只在标题中搜索

curl -X POST "https://api.tengence.com/v1/search"
-H "Content-Type: application/json"
-H "Authorization: Bearer {YOUR_API_KEY}"
-d '{
"query": "ai",
"searchFields": ["title"]
}'


### 18. 欄位選擇 – 限制搜尋欄位

**場景**:只在標題中搜尋```
// JavaScript
const response = await fetch('https://api.tengence.com/v1/search', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer {YOUR_API_KEY}'
  },
  body: JSON.stringify({
    query: 'ai',
    searchFields: ['title']
  })
});
# Python
response = requests.post(
    'https://api.tengence.com/v1/search',
    headers={
        'Content-Type': 'application/json',
        'Authorization': 'Bearer {YOUR_API_KEY}'
    },
    json={
        'query': 'ai',
        'searchFields': ['title']
    }
)

19. 字段选择 – 限制返回字段

场景:只返回 ID 和标题

curl -X POST "https://api.tengence.com/v1/search" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer {YOUR_API_KEY}" \
  -d '{
    "query": "ai",
    "includeFields": ["id", "title", "create_time"]
  }'

19. 欄位選擇 – 限制傳回欄位

場景:只傳回 ID 與標題“`
// JavaScript
const response = await fetch('https://api.tengence.com/v1/search', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer {YOUR_API_KEY}'
},
body: JSON.stringify({
query: 'ai',
includeFields: ['id', 'title', 'create_time']
})
});

Python

response = requests.post(
'https://api.tengence.com/v1/search',
headers={
'Content-Type': 'application/json',
'Authorization': 'Bearer {YOUR_API_KEY}'
},
json={
'query': 'ai',
'includeFields': ['id', 'title', 'create_time']
}
)


---

### 20\. 电商场景 – 完整功能

**场景**:商品搜索,包含排序、高亮、聚合等完整功能

curl -X POST "https://api.tengence.com/v1/search"
-H "Content-Type: application/json"
-H "Authorization: Bearer {YOUR_API_KEY}"
-d '{
"query": "ai",
"page": 1,
"size": 20,
"sortFields": [{"field": "sales_count", "order": "DESC"}],
"highlightFields": ["title", "description"],
"searchFields": ["title", "keywords", "brand"],
"includeFields": ["id", "title", "price", "brand", "sales_count"],
"aggregations": [
{
"name": "by_brand",
"field": "brand",
"type": "terms",
"size": 10,
"sortBy": "count",
"sortOrder": "DESC"
},
{
"name": "by_price",
"field": "price",
"type": "range",
"ranges": [
{"key": "budget", "to": 2000},
{"key": "mid_range", "from": 2000, "to": 5000},
{"key": "premium", "from": 5000}
]
}
]
}'


### 20. 電商場景 – 完整功能

**場景**:商品搜尋,包含排序、高亮、聚合等完整功能```
// JavaScript
const response = await fetch('https://api.tengence.com/v1/search', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer {YOUR_API_KEY}'
  },
  body: JSON.stringify({
    query: 'ai',
    page: 1,
    size: 20,
    sortFields: [{ field: 'sales_count', order: 'DESC' }],
    highlightFields: ['title', 'description'],
    searchFields: ['title', 'keywords', 'brand'],
    includeFields: ['id', 'title', 'price', 'brand', 'sales_count'],
    aggregations: [
      {
        name: 'by_brand',
        field: 'brand',
        type: 'terms',
        size: 10,
        sortBy: 'count',
        sortOrder: 'DESC'
      },
      {
        name: 'by_price',
        field: 'price',
        type: 'range',
        ranges: [
          { key: 'budget', to: 2000 },
          { key: 'mid_range', from: 2000, to: 5000 },
          { key: 'premium', from: 5000 }
        ]
      }
    ]
  })
});
# Python
response = requests.post(
    'https://api.tengence.com/v1/search',
    headers={
        'Content-Type': 'application/json',
        'Authorization': 'Bearer {YOUR_API_KEY}'
    },
    json={
        'query': 'ai',
        'page': 1,
        'size': 20,
        'sortFields': [{'field': 'sales_count', 'order': 'DESC'}],
        'highlightFields': ['title', 'description'],
        'searchFields': ['title', 'keywords', 'brand'],
        'includeFields': ['id', 'title', 'price', 'brand', 'sales_count'],
        'aggregations': [
            {
                'name': 'by_brand',
                'field': 'brand',
                'type': 'terms',
                'size': 10,
                'sortBy': 'count',
                'sortOrder': 'DESC'
            },
            {
                'name': 'by_price',
                'field': 'price',
                'type': 'range',
                'ranges': [
                    {'key': 'budget', 'to': 2000},
                    {'key': 'mid_range', 'from': 2000, 'to': 5000},
                    {'key': 'premium', 'from': 5000}
                ]
            }
        ]
    }
)

21. 内容搜索 – 完整功能

场景:内容搜索,按时间排序,支持日期趋势和来源聚合

curl -X POST "https://api.tengence.com/v1/search" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer {YOUR_API_KEY}" \
  -d '{
    "query": "ai",
    "page": 1,
    "size": 10,
    "sortFields": [{"field": "publish_time", "order": "DESC"}],
    "highlightFields": ["title", "summary"],
    "aggregations": [
      {
        "name": "by_date",
        "field": "publish_time",
        "type": "date_histogram",
        "interval": "1w"
      },
      {
        "name": "by_source",
        "field": "source",
        "type": "terms",
        "size": 20
      }
    ]
  }'

21. 內容搜尋 – 完整功能

場景:內容搜尋,按時間排序,支援日期趨勢與來源聚合“`
// JavaScript
const response = await fetch('https://api.tengence.com/v1/search', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer {YOUR_API_KEY}'
},
body: JSON.stringify({
query: 'ai',
page: 1,
size: 10,
sortFields: [{ field: 'publish_time', order: 'DESC' }],
highlightFields: ['title', 'summary'],
aggregations: [
{
name: 'by_date',
field: 'publish_time',
type: 'date_histogram',
interval: '1w'
},
{
name: 'by_source',
field: 'source',
type: 'terms',
size: 20
}
]
})
});

Python

response = requests.post(
'https://api.tengence.com/v1/search',
headers={
'Content-Type': 'application/json',
'Authorization': 'Bearer {YOUR_API_KEY}'
},
json={
'query': 'ai',
'page': 1,
'size': 10,
'sortFields': [{'field': 'publish_time', 'order': 'DESC'}],
'highlightFields': ['title', 'summary'],
'aggregations': [
{
'name': 'by_date',
'field': 'publish_time',
'type': 'date_histogram',
'interval': '1w'
},
{
'name': 'by_source',
'field': 'source',
'type': 'terms',
'size': 20
}
]
}
)


---

### 22\. 日志分析 – 完整功能

**场景**:日志分析搜索,按错误类型和服务名聚合

curl -X POST "https://api.tengence.com/v1/search"
-H "Content-Type: application/json"
-H "Authorization: Bearer {YOUR_API_KEY}"
-d '{
"query": "ERROR",
"page": 1,
"size": 50,
"sortFields": [{"field": "timestamp", "order": "DESC"}],
"aggregations": [
{
"name": "errors_by_hour",
"field": "timestamp",
"type": "date_histogram",
"interval": "1h"
},
{
"name": "errors_by_code",
"field": "error_code",
"type": "terms",
"size": 20
},
{
"name": "errors_by_service",
"field": "service_name",
"type": "terms",
"size": 10
}
]
}'


### 22. 日誌分析 – 完整功能

**場景**:日誌分析搜尋,按錯誤類型與服務名稱聚合```
// JavaScript
const response = await fetch('https://api.tengence.com/v1/search', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer {YOUR_API_KEY}'
  },
  body: JSON.stringify({
    query: 'ERROR',
    page: 1,
    size: 50,
    sortFields: [{ field: 'timestamp', order: 'DESC' }],
    aggregations: [
      {
        name: 'errors_by_hour',
        field: 'timestamp',
        type: 'date_histogram',
        interval: '1h'
      },
      {
        name: 'errors_by_code',
        field: 'error_code',
        type: 'terms',
        size: 20
      },
      {
        name: 'errors_by_service',
        field: 'service_name',
        type: 'terms',
        size: 10
      }
    ]
  })
});
# Python
response = requests.post(
    'https://api.tengence.com/v1/search',
    headers={
        'Content-Type': 'application/json',
        'Authorization': 'Bearer {YOUR_API_KEY}'
    },
    json={
        'query': 'ERROR',
        'page': 1,
        'size': 50,
        'sortFields': [{'field': 'timestamp', 'order': 'DESC'}],
        'aggregations': [
            {
                'name': 'errors_by_hour',
                'field': 'timestamp',
                'type': 'date_histogram',
                'interval': '1h'
            },
            {
                'name': 'errors_by_code',
                'field': 'error_code',
                'type': 'terms',
                'size': 20
            },
            {
                'name': 'errors_by_service',
                'field': 'service_name',
                'type': 'terms',
                'size': 10
            }
        ]
    }
)

23. 实时监控 – 分钟级统计

场景:按分钟统计最近一小时的实时数据

curl -X POST "https://api.tengence.com/v1/search" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer {YOUR_API_KEY}" \
  -d '{
    "query": "ai",
    "aggregations": [{
      "name": "realtime_data",
      "field": "created_at",
      "type": "date_histogram",
      "interval": "1m"
    }],
    "sortFields": [{"field": "created_at", "order": "DESC"}]
  }'

23. 即時監控 – 分鐘級統計

場景:按分鐘統計最近一小時的即時數據“`
// JavaScript
const response = await fetch('https://api.tengence.com/v1/search', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer {YOUR_API_KEY}'
},
body: JSON.stringify({
query: 'ai',
aggregations: [{
name: 'realtime_data',
field: 'created_at',
type: 'date_histogram',
interval: '1m'
}],
sortFields: [{ field: 'created_at', order: 'DESC' }]
})
});

Python

response = requests.post(
'https://api.tengence.com/v1/search',
headers={
'Content-Type': 'application/json',
'Authorization': 'Bearer {YOUR_API_KEY}'
},
json={
'query': 'ai',
'aggregations': [{
'name': 'realtime_data',
'field': 'created_at',
'type': 'date_histogram',
'interval': '1m'
}],
'sortFields': [{'field': 'created_at', 'order': 'DESC'}]
}
)


---

### 24\. 综合业务场景

**场景**:搜索,结合过滤、排序、高亮、聚合等全部功能

curl -X POST "https://api.tengence.com/v1/search"
-H "Content-Type: application/json"
-H "Authorization: Bearer {YOUR_API_KEY}"
-d '{
"query": "ai",
"page": 1,
"size": 20,
"filters": [
{"field": "price", "operator": "gte", "value": 2000},
{"field": "price", "operator": "lte", "value": 5000},
{"field": "brand", "operator": "in", "values": ["Apple", "华为"]},
{"field": "status", "operator": "eq", "value": "on_sale"}
],
"sortFields": [
{"field": "sales_count", "order": "DESC"},
{"field": "rating", "order": "DESC"}
],
"highlightFields": ["title", "description"],
"searchFields": ["title", "keywords", "brand"],
"includeFields": ["id", "title", "price", "brand", "sales_count", "rating"],
"aggregations": [
{
"name": "by_brand",
"field": "brand",
"type": "terms",
"size": 10
},
{
"name": "by_price_range",
"field": "price",
"type": "range",
"ranges": [
{"key": "budget", "to": 3000},
{"key": "mid_range", "from": 3000, "to": 4000},
{"key": "premium", "from": 4000}
]
}
]
}'


### 24. 綜合業務場景

**場景**:搜尋,結合過濾、排序、高亮、聚合等全部功能```
// JavaScript
const response = await fetch('https://api.tengence.com/v1/search', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer {YOUR_API_KEY}'
  },
  body: JSON.stringify({
    query: 'ai',
    page: 1,
    size: 20,
    filters: [
      { field: 'price', operator: 'gte', value: 2000 },
      { field: 'price', operator: 'lte', value: 5000 },
      { field: 'brand', operator: 'in', values: ['Apple', '华为'] },
      { field: 'status', operator: 'eq', value: 'on_sale' }
    ],
    sortFields: [
      { field: 'sales_count', order: 'DESC' },
      { field: 'rating', order: 'DESC' }
    ],
    highlightFields: ['title', 'description'],
    searchFields: ['title', 'keywords', 'brand'],
    includeFields: ['id', 'title', 'price', 'brand', 'sales_count', 'rating'],
    aggregations: [
      {
        name: 'by_brand',
        field: 'brand',
        type: 'terms',
        size: 10
      },
      {
        name: 'by_price_range',
        field: 'price',
        type: 'range',
        ranges: [
          { key: 'budget', to: 3000 },
          { key: 'mid_range', from: 3000, to: 4000 },
          { key: 'premium', from: 4000 }
        ]
      }
    ]
  })
});
# Python
response = requests.post(
    'https://api.tengence.com/v1/search',
    headers={
        'Content-Type': 'application/json',
        'Authorization': 'Bearer {YOUR_API_KEY}'
    },
    json={
        'query': 'ai',
        'page': 1,
        'size': 20,
        'filters': [
            {'field': 'price', 'operator': 'gte', 'value': 2000},
            {'field': 'price', 'operator': 'lte', 'value': 5000},
            {'field': 'brand', 'operator': 'in', 'values': ['Apple', '华为']},
            {'field': 'status', 'operator': 'eq', 'value': 'on_sale'}
        ],
        'sortFields': [
            {'field': 'sales_count', 'order': 'DESC'},
            {'field': 'rating', 'order': 'DESC'}
        ],
        'highlightFields': ['title', 'description'],
        'searchFields': ['title', 'keywords', 'brand'],
        'includeFields': ['id', 'title', 'price', 'brand', 'sales_count', 'rating'],
        'aggregations': [
            {
                'name': 'by_brand',
                'field': 'brand',
                'type': 'terms',
                'size': 10
            },
            {
                'name': 'by_price_range',
                'field': 'price',
                'type': 'range',
                'ranges': [
                    {'key': 'budget', 'to': 3000},
                    {'key': 'mid_range', 'from': 3000, 'to': 4000},
                    {'key': 'premium', 'from': 4000}
                ]
            }
        ]
    }
)

常見問題

Q:如何獲取 API Key?

登入通智控制台(https://console.tengence.com),於「應用詳情」頁面中獲取 API Key。


Q:日期欄位支援哪些格式?

日期欄位支援多種格式:


Q:如何設定分頁參數?

使用 page 與 size 參數:


Q:如何同時使用多個過濾條件?

在 filters 陣列中加入多個過濾物件,多個條件之間為 AND 關係。


Q:聚合結果如何排序?

對於 terms 聚合,可使用 sortBy 與 sortOrder 參數:


Q:搜尋不到結果怎麼辦?

請檢查:

  1. 搜尋關鍵字是否正確
  2. 索引中是否有相關資料
  3. 過濾條件是否過於嚴格
  4. 欄位名稱是否正確(使用底線命名法)

Q:如何限制搜尋的欄位範圍?

使用 searchFields 參數指定要搜尋的欄位清單。


Q:如何只傳回需要的欄位?

使用 includeFields 參數指定要傳回的欄位清單。


相關資源


下一篇: 通智雲數據中心使用說明:API 推送、MySQL 與行為數據集接入 →
諮詢
二維碼

企業微信