Commit f27a8d90508eae062e79cf4d73abbf7a7bf6fb98
1 parent
8e081187
ES文档维护
Showing
3 changed files
with
49 additions
and
41 deletions
Show diff stats
| @@ -4,6 +4,7 @@ | @@ -4,6 +4,7 @@ | ||
| 4 | ES_HOST=http://localhost:9200 | 4 | ES_HOST=http://localhost:9200 |
| 5 | ES_USERNAME=saas | 5 | ES_USERNAME=saas |
| 6 | ES_PASSWORD=4hOaLaf41y2VuI8y | 6 | ES_PASSWORD=4hOaLaf41y2VuI8y |
| 7 | +ES_AUTH="${ES_USERNAME}:${ES_PASSWORD}" | ||
| 7 | 8 | ||
| 8 | # Redis Configuration (Optional) - AI 生产 10.200.16.14:6479 | 9 | # Redis Configuration (Optional) - AI 生产 10.200.16.14:6479 |
| 9 | REDIS_HOST=10.200.16.14 | 10 | REDIS_HOST=10.200.16.14 |
.env.example
| @@ -8,6 +8,7 @@ | @@ -8,6 +8,7 @@ | ||
| 8 | ES_HOST=http://localhost:9200 | 8 | ES_HOST=http://localhost:9200 |
| 9 | ES_USERNAME=saas | 9 | ES_USERNAME=saas |
| 10 | ES_PASSWORD= | 10 | ES_PASSWORD= |
| 11 | +ES_AUTH="${ES_USERNAME}:${ES_PASSWORD}" | ||
| 11 | 12 | ||
| 12 | # Redis (生产默认 10.200.16.14:6479,密码见 docs/QUICKSTART.md §1.6) | 13 | # Redis (生产默认 10.200.16.14:6479,密码见 docs/QUICKSTART.md §1.6) |
| 13 | REDIS_HOST=10.200.16.14 | 14 | REDIS_HOST=10.200.16.14 |
docs/常用查询 - ES.md
| 1 | - | ||
| 2 | - | ||
| 3 | ## Elasticsearch 排查流程 | 1 | ## Elasticsearch 排查流程 |
| 4 | 2 | ||
| 3 | +使用前加载环境变量: | ||
| 4 | +```bash | ||
| 5 | +set -a; source .env; set +a | ||
| 6 | +# 或直接 export | ||
| 7 | +export ES_AUTH="saas:4hOaLaf41y2VuI8y" | ||
| 8 | +export ES="http://127.0.0.1:9200" | ||
| 9 | +``` | ||
| 10 | + | ||
| 5 | ### 1. 集群健康状态 | 11 | ### 1. 集群健康状态 |
| 6 | 12 | ||
| 7 | ```bash | 13 | ```bash |
| 8 | # 集群整体健康(green / yellow / red) | 14 | # 集群整体健康(green / yellow / red) |
| 9 | -curl -s -u 'saas:4hOaLaf41y2VuI8y' 'http://127.0.0.1:9200/_cluster/health?pretty' | 15 | +curl -s -u "$ES_AUTH" 'http://127.0.0.1:9200/_cluster/health?pretty' |
| 10 | ``` | 16 | ``` |
| 11 | 17 | ||
| 12 | ### 2. 索引概览 | 18 | ### 2. 索引概览 |
| 13 | 19 | ||
| 14 | ```bash | 20 | ```bash |
| 15 | # 查看所有租户索引状态与体积 | 21 | # 查看所有租户索引状态与体积 |
| 16 | -curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/_cat/indices/search_products_tenant_*?v' | 22 | +curl -u "$ES_AUTH" -X GET 'http://localhost:9200/_cat/indices/search_products_tenant_*?v' |
| 17 | 23 | ||
| 18 | # 或查看全部索引 | 24 | # 或查看全部索引 |
| 19 | -curl -s -u 'saas:4hOaLaf41y2VuI8y' 'http://127.0.0.1:9200/_cat/indices?v' | 25 | +curl -s -u "$ES_AUTH" 'http://127.0.0.1:9200/_cat/indices?v' |
| 20 | ``` | 26 | ``` |
| 21 | 27 | ||
| 22 | ### 3. 分片分布 | 28 | ### 3. 分片分布 |
| 23 | 29 | ||
| 24 | ```bash | 30 | ```bash |
| 25 | # 查看分片在各节点的分布情况 | 31 | # 查看分片在各节点的分布情况 |
| 26 | -curl -s -u 'saas:4hOaLaf41y2VuI8y' 'http://127.0.0.1:9200/_cat/shards?v' | 32 | +curl -s -u "$ES_AUTH" 'http://127.0.0.1:9200/_cat/shards?v' |
| 27 | ``` | 33 | ``` |
| 28 | 34 | ||
| 29 | ### 4. 分配诊断(如有异常) | 35 | ### 4. 分配诊断(如有异常) |
| 30 | 36 | ||
| 31 | ```bash | 37 | ```bash |
| 32 | # 当 health 非 green 或 shards 状态异常时,定位具体原因 | 38 | # 当 health 非 green 或 shards 状态异常时,定位具体原因 |
| 33 | -curl -s -u 'saas:4hOaLaf41y2VuI8y' -X POST 'http://127.0.0.1:9200/_cluster/allocation/explain?pretty' \ | 39 | +curl -s -u "$ES_AUTH" -X POST 'http://127.0.0.1:9200/_cluster/allocation/explain?pretty' \ |
| 34 | -H 'Content-Type: application/json' \ | 40 | -H 'Content-Type: application/json' \ |
| 35 | -d '{"index":"search_products_tenant_163","shard":0,"primary":true}' | 41 | -d '{"index":"search_products_tenant_163","shard":0,"primary":true}' |
| 36 | ``` | 42 | ``` |
| @@ -69,7 +75,7 @@ journalctl -u elasticsearch -f | @@ -69,7 +75,7 @@ journalctl -u elasticsearch -f | ||
| 69 | ```bash | 75 | ```bash |
| 70 | # 按需替换:索引名、账号密码、ES 地址 | 76 | # 按需替换:索引名、账号密码、ES 地址 |
| 71 | INDEX="search_products_tenant_163" | 77 | INDEX="search_products_tenant_163" |
| 72 | -AUTH='saas:4hOaLaf41y2VuI8y' | 78 | +AUTH="$ES_AUTH" |
| 73 | ES="http://localhost:9200" | 79 | ES="http://localhost:9200" |
| 74 | 80 | ||
| 75 | # 1) 关闭索引(写入类请求会失败,注意维护窗口) | 81 | # 1) 关闭索引(写入类请求会失败,注意维护窗口) |
| @@ -141,7 +147,7 @@ systemctl / df / 日志 → 系统层验证 | @@ -141,7 +147,7 @@ systemctl / df / 日志 → 系统层验证 | ||
| 141 | 147 | ||
| 142 | #### 查询指定 spu_id 的商品(返回 title) | 148 | #### 查询指定 spu_id 的商品(返回 title) |
| 143 | ```bash | 149 | ```bash |
| 144 | -curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_170/_search?pretty' -H 'Content-Type: application/json' -d '{ | 150 | +curl -u "$ES_AUTH" -X GET 'http://localhost:9200/search_products_tenant_170/_search?pretty' -H 'Content-Type: application/json' -d '{ |
| 145 | "size": 11, | 151 | "size": 11, |
| 146 | "_source": ["title"], | 152 | "_source": ["title"], |
| 147 | "query": { | 153 | "query": { |
| @@ -156,7 +162,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | @@ -156,7 +162,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | ||
| 156 | 162 | ||
| 157 | #### 查询所有商品(返回 title) | 163 | #### 查询所有商品(返回 title) |
| 158 | ```bash | 164 | ```bash |
| 159 | -curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_170/_search?pretty' -H 'Content-Type: application/json' -d '{ | 165 | +curl -u "$ES_AUTH" -X GET 'http://localhost:9200/search_products_tenant_170/_search?pretty' -H 'Content-Type: application/json' -d '{ |
| 160 | "size": 100, | 166 | "size": 100, |
| 161 | "_source": ["title"], | 167 | "_source": ["title"], |
| 162 | "query": { | 168 | "query": { |
| @@ -167,7 +173,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | @@ -167,7 +173,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | ||
| 167 | 173 | ||
| 168 | #### 查询指定 spu_id 的商品(返回 title、keywords、tags) | 174 | #### 查询指定 spu_id 的商品(返回 title、keywords、tags) |
| 169 | ```bash | 175 | ```bash |
| 170 | -curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_170/_search?pretty' -H 'Content-Type: application/json' -d '{ | 176 | +curl -u "$ES_AUTH" -X GET 'http://localhost:9200/search_products_tenant_170/_search?pretty' -H 'Content-Type: application/json' -d '{ |
| 171 | "size": 5, | 177 | "size": 5, |
| 172 | "_source": ["title", "keywords", "tags"], | 178 | "_source": ["title", "keywords", "tags"], |
| 173 | "query": { | 179 | "query": { |
| @@ -182,7 +188,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | @@ -182,7 +188,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | ||
| 182 | 188 | ||
| 183 | #### 组合查询:匹配标题 + 过滤标签 | 189 | #### 组合查询:匹配标题 + 过滤标签 |
| 184 | ```bash | 190 | ```bash |
| 185 | -curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_170/_search?pretty' -H 'Content-Type: application/json' -d '{ | 191 | +curl -u "$ES_AUTH" -X GET 'http://localhost:9200/search_products_tenant_170/_search?pretty' -H 'Content-Type: application/json' -d '{ |
| 186 | "size": 1, | 192 | "size": 1, |
| 187 | "_source": ["title", "keywords", "tags"], | 193 | "_source": ["title", "keywords", "tags"], |
| 188 | "query": { | 194 | "query": { |
| @@ -206,7 +212,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | @@ -206,7 +212,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | ||
| 206 | 212 | ||
| 207 | #### 组合查询:匹配标题 + 过滤租户(冗余示例) | 213 | #### 组合查询:匹配标题 + 过滤租户(冗余示例) |
| 208 | ```bash | 214 | ```bash |
| 209 | -curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_170/_search?pretty' -H 'Content-Type: application/json' -d '{ | 215 | +curl -u "$ES_AUTH" -X GET 'http://localhost:9200/search_products_tenant_170/_search?pretty' -H 'Content-Type: application/json' -d '{ |
| 210 | "size": 1, | 216 | "size": 1, |
| 211 | "_source": ["title"], | 217 | "_source": ["title"], |
| 212 | "query": { | 218 | "query": { |
| @@ -234,7 +240,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | @@ -234,7 +240,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | ||
| 234 | 240 | ||
| 235 | #### 测试 index_ik 分析器 | 241 | #### 测试 index_ik 分析器 |
| 236 | ```bash | 242 | ```bash |
| 237 | -curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_170/_analyze' -H 'Content-Type: application/json' -d '{ | 243 | +curl -u "$ES_AUTH" -X GET 'http://localhost:9200/search_products_tenant_170/_analyze' -H 'Content-Type: application/json' -d '{ |
| 238 | "analyzer": "index_ik", | 244 | "analyzer": "index_ik", |
| 239 | "text": "14寸第4代-眼珠实身冰雪公仔带手动大推车,搪胶雪宝宝" | 245 | "text": "14寸第4代-眼珠实身冰雪公仔带手动大推车,搪胶雪宝宝" |
| 240 | }' | 246 | }' |
| @@ -242,7 +248,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | @@ -242,7 +248,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | ||
| 242 | 248 | ||
| 243 | #### 测试 query_ik 分析器 | 249 | #### 测试 query_ik 分析器 |
| 244 | ```bash | 250 | ```bash |
| 245 | -curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_170/_analyze' -H 'Content-Type: application/json' -d '{ | 251 | +curl -u "$ES_AUTH" -X GET 'http://localhost:9200/search_products_tenant_170/_analyze' -H 'Content-Type: application/json' -d '{ |
| 246 | "analyzer": "query_ik", | 252 | "analyzer": "query_ik", |
| 247 | "text": "14寸第4代-眼珠实身冰雪公仔带手动大推车,搪胶雪宝宝" | 253 | "text": "14寸第4代-眼珠实身冰雪公仔带手动大推车,搪胶雪宝宝" |
| 248 | }' | 254 | }' |
| @@ -254,7 +260,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | @@ -254,7 +260,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | ||
| 254 | 260 | ||
| 255 | #### 多字段匹配 + 聚合(category1、color、size、material) | 261 | #### 多字段匹配 + 聚合(category1、color、size、material) |
| 256 | ```bash | 262 | ```bash |
| 257 | -curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_170/_search?pretty' -H 'Content-Type: application/json' -d '{ | 263 | +curl -u "$ES_AUTH" -X GET 'http://localhost:9200/search_products_tenant_170/_search?pretty' -H 'Content-Type: application/json' -d '{ |
| 258 | "size": 1, | 264 | "size": 1, |
| 259 | "from": 0, | 265 | "from": 0, |
| 260 | "query": { | 266 | "query": { |
| @@ -364,7 +370,7 @@ GET /search_products_tenant_2/_search | @@ -364,7 +370,7 @@ GET /search_products_tenant_2/_search | ||
| 364 | 370 | ||
| 365 | #### 按 spu_id 查询(通用索引) | 371 | #### 按 spu_id 查询(通用索引) |
| 366 | ```bash | 372 | ```bash |
| 367 | -curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products/_search?pretty' -H 'Content-Type: application/json' -d '{ | 373 | +curl -u "$ES_AUTH" -X GET 'http://localhost:9200/search_products/_search?pretty' -H 'Content-Type: application/json' -d '{ |
| 368 | "size": 5, | 374 | "size": 5, |
| 369 | "query": { | 375 | "query": { |
| 370 | "bool": { | 376 | "bool": { |
| @@ -381,7 +387,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products/_s | @@ -381,7 +387,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products/_s | ||
| 381 | ### 5. 统计租户总文档数 | 387 | ### 5. 统计租户总文档数 |
| 382 | 388 | ||
| 383 | ```bash | 389 | ```bash |
| 384 | -curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_170/_count?pretty' -H 'Content-Type: application/json' -d '{ | 390 | +curl -u "$ES_AUTH" -X GET 'http://localhost:9200/search_products_tenant_170/_count?pretty' -H 'Content-Type: application/json' -d '{ |
| 385 | "query": { | 391 | "query": { |
| 386 | "match_all": {} | 392 | "match_all": {} |
| 387 | } | 393 | } |
| @@ -396,7 +402,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | @@ -396,7 +402,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | ||
| 396 | 402 | ||
| 397 | #### 1.1 查询特定租户的商品,显示分面相关字段 | 403 | #### 1.1 查询特定租户的商品,显示分面相关字段 |
| 398 | ```bash | 404 | ```bash |
| 399 | -curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{ | 405 | +curl -u "$ES_AUTH" -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{ |
| 400 | "query": { | 406 | "query": { |
| 401 | "term": { "tenant_id": "162" } | 407 | "term": { "tenant_id": "162" } |
| 402 | }, | 408 | }, |
| @@ -411,7 +417,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | @@ -411,7 +417,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | ||
| 411 | 417 | ||
| 412 | #### 1.2 验证 category1_name 字段是否有数据 | 418 | #### 1.2 验证 category1_name 字段是否有数据 |
| 413 | ```bash | 419 | ```bash |
| 414 | -curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{ | 420 | +curl -u "$ES_AUTH" -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{ |
| 415 | "query": { | 421 | "query": { |
| 416 | "bool": { | 422 | "bool": { |
| 417 | "filter": [ | 423 | "filter": [ |
| @@ -426,7 +432,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | @@ -426,7 +432,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | ||
| 426 | 432 | ||
| 427 | #### 1.3 验证 specifications 字段是否有数据 | 433 | #### 1.3 验证 specifications 字段是否有数据 |
| 428 | ```bash | 434 | ```bash |
| 429 | -curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{ | 435 | +curl -u "$ES_AUTH" -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{ |
| 430 | "query": { | 436 | "query": { |
| 431 | "bool": { | 437 | "bool": { |
| 432 | "filter": [ | 438 | "filter": [ |
| @@ -445,7 +451,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | @@ -445,7 +451,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | ||
| 445 | 451 | ||
| 446 | #### 2.1 category1_name 分面聚合 | 452 | #### 2.1 category1_name 分面聚合 |
| 447 | ```bash | 453 | ```bash |
| 448 | -curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{ | 454 | +curl -u "$ES_AUTH" -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{ |
| 449 | "query": { "match_all": {} }, | 455 | "query": { "match_all": {} }, |
| 450 | "size": 0, | 456 | "size": 0, |
| 451 | "aggs": { | 457 | "aggs": { |
| @@ -458,7 +464,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | @@ -458,7 +464,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | ||
| 458 | 464 | ||
| 459 | #### 2.2 specifications.color 分面聚合 | 465 | #### 2.2 specifications.color 分面聚合 |
| 460 | ```bash | 466 | ```bash |
| 461 | -curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{ | 467 | +curl -u "$ES_AUTH" -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{ |
| 462 | "query": { "match_all": {} }, | 468 | "query": { "match_all": {} }, |
| 463 | "size": 0, | 469 | "size": 0, |
| 464 | "aggs": { | 470 | "aggs": { |
| @@ -479,7 +485,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | @@ -479,7 +485,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | ||
| 479 | 485 | ||
| 480 | #### 2.3 specifications.size 分面聚合 | 486 | #### 2.3 specifications.size 分面聚合 |
| 481 | ```bash | 487 | ```bash |
| 482 | -curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{ | 488 | +curl -u "$ES_AUTH" -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{ |
| 483 | "query": { "match_all": {} }, | 489 | "query": { "match_all": {} }, |
| 484 | "size": 0, | 490 | "size": 0, |
| 485 | "aggs": { | 491 | "aggs": { |
| @@ -500,7 +506,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | @@ -500,7 +506,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | ||
| 500 | 506 | ||
| 501 | #### 2.4 specifications.material 分面聚合 | 507 | #### 2.4 specifications.material 分面聚合 |
| 502 | ```bash | 508 | ```bash |
| 503 | -curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{ | 509 | +curl -u "$ES_AUTH" -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{ |
| 504 | "query": { "match_all": {} }, | 510 | "query": { "match_all": {} }, |
| 505 | "size": 0, | 511 | "size": 0, |
| 506 | "aggs": { | 512 | "aggs": { |
| @@ -521,7 +527,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | @@ -521,7 +527,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | ||
| 521 | 527 | ||
| 522 | #### 2.5 综合分面聚合(category + color + size + material) | 528 | #### 2.5 综合分面聚合(category + color + size + material) |
| 523 | ```bash | 529 | ```bash |
| 524 | -curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{ | 530 | +curl -u "$ES_AUTH" -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{ |
| 525 | "query": { "match_all": {} }, | 531 | "query": { "match_all": {} }, |
| 526 | "size": 0, | 532 | "size": 0, |
| 527 | "aggs": { | 533 | "aggs": { |
| @@ -563,7 +569,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | @@ -563,7 +569,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | ||
| 563 | 569 | ||
| 564 | #### 3.1 查看 specifications 的 name 字段有哪些值 | 570 | #### 3.1 查看 specifications 的 name 字段有哪些值 |
| 565 | ```bash | 571 | ```bash |
| 566 | -curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products/_search?pretty' -H 'Content-Type: application/json' -d '{ | 572 | +curl -u "$ES_AUTH" -X GET 'http://localhost:9200/search_products/_search?pretty' -H 'Content-Type: application/json' -d '{ |
| 567 | "query": { "term": { "tenant_id": "162" } }, | 573 | "query": { "term": { "tenant_id": "162" } }, |
| 568 | "size": 0, | 574 | "size": 0, |
| 569 | "aggs": { | 575 | "aggs": { |
| @@ -579,7 +585,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products/_s | @@ -579,7 +585,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products/_s | ||
| 579 | 585 | ||
| 580 | #### 3.2 查看某个商品的完整 specifications 数据 | 586 | #### 3.2 查看某个商品的完整 specifications 数据 |
| 581 | ```bash | 587 | ```bash |
| 582 | -curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products/_search?pretty' -H 'Content-Type: application/json' -d '{ | 588 | +curl -u "$ES_AUTH" -X GET 'http://localhost:9200/search_products/_search?pretty' -H 'Content-Type: application/json' -d '{ |
| 583 | "query": { | 589 | "query": { |
| 584 | "bool": { | 590 | "bool": { |
| 585 | "filter": [ | 591 | "filter": [ |
| @@ -600,7 +606,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products/_s | @@ -600,7 +606,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products/_s | ||
| 600 | **keyword 精确匹配**(示例词:中文 `法式风格`,英文 `long skirt`) | 606 | **keyword 精确匹配**(示例词:中文 `法式风格`,英文 `long skirt`) |
| 601 | 607 | ||
| 602 | ```bash | 608 | ```bash |
| 603 | -curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{ | 609 | +curl -u "$ES_AUTH" -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{ |
| 604 | "size": 1, | 610 | "size": 1, |
| 605 | "_source": ["spu_id", "title", "enriched_attributes"], | 611 | "_source": ["spu_id", "title", "enriched_attributes"], |
| 606 | "query": { | 612 | "query": { |
| @@ -623,7 +629,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | @@ -623,7 +629,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | ||
| 623 | **text 全文匹配**(经 `index_ik` / `english` 分词;可与上式对照) | 629 | **text 全文匹配**(经 `index_ik` / `english` 分词;可与上式对照) |
| 624 | 630 | ||
| 625 | ```bash | 631 | ```bash |
| 626 | -curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{ | 632 | +curl -u "$ES_AUTH" -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{ |
| 627 | "size": 1, | 633 | "size": 1, |
| 628 | "_source": ["spu_id", "title", "enriched_attributes"], | 634 | "_source": ["spu_id", "title", "enriched_attributes"], |
| 629 | "query": { | 635 | "query": { |
| @@ -650,7 +656,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | @@ -650,7 +656,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | ||
| 650 | **keyword 精确匹配** | 656 | **keyword 精确匹配** |
| 651 | 657 | ||
| 652 | ```bash | 658 | ```bash |
| 653 | -curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{ | 659 | +curl -u "$ES_AUTH" -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{ |
| 654 | "size": 1, | 660 | "size": 1, |
| 655 | "_source": ["spu_id", "title", "option1_values"], | 661 | "_source": ["spu_id", "title", "option1_values"], |
| 656 | "query": { | 662 | "query": { |
| @@ -668,7 +674,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | @@ -668,7 +674,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | ||
| 668 | **text 全文匹配** | 674 | **text 全文匹配** |
| 669 | 675 | ||
| 670 | ```bash | 676 | ```bash |
| 671 | -curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{ | 677 | +curl -u "$ES_AUTH" -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{ |
| 672 | "size": 1, | 678 | "size": 1, |
| 673 | "_source": ["spu_id", "title", "option1_values"], | 679 | "_source": ["spu_id", "title", "option1_values"], |
| 674 | "query": { | 680 | "query": { |
| @@ -688,7 +694,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | @@ -688,7 +694,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | ||
| 688 | **keyword 精确匹配** | 694 | **keyword 精确匹配** |
| 689 | 695 | ||
| 690 | ```bash | 696 | ```bash |
| 691 | -curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{ | 697 | +curl -u "$ES_AUTH" -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{ |
| 692 | "size": 1, | 698 | "size": 1, |
| 693 | "_source": ["spu_id", "title", "enriched_tags"], | 699 | "_source": ["spu_id", "title", "enriched_tags"], |
| 694 | "query": { | 700 | "query": { |
| @@ -706,7 +712,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | @@ -706,7 +712,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | ||
| 706 | **text 全文匹配** | 712 | **text 全文匹配** |
| 707 | 713 | ||
| 708 | ```bash | 714 | ```bash |
| 709 | -curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{ | 715 | +curl -u "$ES_AUTH" -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{ |
| 710 | "size": 1, | 716 | "size": 1, |
| 711 | "_source": ["spu_id", "title", "enriched_tags"], | 717 | "_source": ["spu_id", "title", "enriched_tags"], |
| 712 | "query": { | 718 | "query": { |
| @@ -726,7 +732,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | @@ -726,7 +732,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | ||
| 726 | > `specifications` 为 **nested**,`value_keyword` 为整词匹配;`value_text.*` 可同时 `term` 子字段或 `match` 主 text。 | 732 | > `specifications` 为 **nested**,`value_keyword` 为整词匹配;`value_text.*` 可同时 `term` 子字段或 `match` 主 text。 |
| 727 | 733 | ||
| 728 | ```bash | 734 | ```bash |
| 729 | -curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{ | 735 | +curl -u "$ES_AUTH" -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{ |
| 730 | "size": 1, | 736 | "size": 1, |
| 731 | "_source": ["spu_id", "title", "specifications"], | 737 | "_source": ["spu_id", "title", "specifications"], |
| 732 | "query": { | 738 | "query": { |
| @@ -758,7 +764,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | @@ -758,7 +764,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | ||
| 758 | 764 | ||
| 759 | #### 4.1 统计有 category1_name 的文档数量 | 765 | #### 4.1 统计有 category1_name 的文档数量 |
| 760 | ```bash | 766 | ```bash |
| 761 | -curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_163/_count?pretty' -H 'Content-Type: application/json' -d '{ | 767 | +curl -u "$ES_AUTH" -X GET 'http://localhost:9200/search_products_tenant_163/_count?pretty' -H 'Content-Type: application/json' -d '{ |
| 762 | "query": { | 768 | "query": { |
| 763 | "bool": { | 769 | "bool": { |
| 764 | "filter": [ | 770 | "filter": [ |
| @@ -771,7 +777,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | @@ -771,7 +777,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | ||
| 771 | 777 | ||
| 772 | #### 4.2 统计有 specifications 的文档数量 | 778 | #### 4.2 统计有 specifications 的文档数量 |
| 773 | ```bash | 779 | ```bash |
| 774 | -curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_163/_count?pretty' -H 'Content-Type: application/json' -d '{ | 780 | +curl -u "$ES_AUTH" -X GET 'http://localhost:9200/search_products_tenant_163/_count?pretty' -H 'Content-Type: application/json' -d '{ |
| 775 | "query": { | 781 | "query": { |
| 776 | "bool": { | 782 | "bool": { |
| 777 | "filter": [ | 783 | "filter": [ |
| @@ -788,7 +794,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | @@ -788,7 +794,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | ||
| 788 | 794 | ||
| 789 | #### 5.1 查找没有 category1_name 但有 category 的文档(MySQL 有数据但 ES 没有) | 795 | #### 5.1 查找没有 category1_name 但有 category 的文档(MySQL 有数据但 ES 没有) |
| 790 | ```bash | 796 | ```bash |
| 791 | -curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{ | 797 | +curl -u "$ES_AUTH" -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{ |
| 792 | "query": { | 798 | "query": { |
| 793 | "bool": { | 799 | "bool": { |
| 794 | "filter": [ | 800 | "filter": [ |
| @@ -806,7 +812,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | @@ -806,7 +812,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te | ||
| 806 | 812 | ||
| 807 | #### 5.2 查找有 option 但没有 specifications 的文档(数据转换问题) | 813 | #### 5.2 查找有 option 但没有 specifications 的文档(数据转换问题) |
| 808 | ```bash | 814 | ```bash |
| 809 | -curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{ | 815 | +curl -u "$ES_AUTH" -X GET 'http://localhost:9200/search_products_tenant_163/_search?pretty' -H 'Content-Type: application/json' -d '{ |
| 810 | "query": { | 816 | "query": { |
| 811 | "bool": { | 817 | "bool": { |
| 812 | "filter": [ | 818 | "filter": [ |
| @@ -862,7 +868,7 @@ GET search_products_tenant_163/_mapping | @@ -862,7 +868,7 @@ GET search_products_tenant_163/_mapping | ||
| 862 | GET search_products_tenant_163/_field_caps?fields=* | 868 | GET search_products_tenant_163/_field_caps?fields=* |
| 863 | 869 | ||
| 864 | ```bash | 870 | ```bash |
| 865 | -curl -u 'saas:4hOaLaf41y2VuI8y' -X POST \ | 871 | +curl -u "$ES_AUTH" -X POST \ |
| 866 | 'http://localhost:9200/search_products_tenant_163/_count' \ | 872 | 'http://localhost:9200/search_products_tenant_163/_count' \ |
| 867 | -H 'Content-Type: application/json' \ | 873 | -H 'Content-Type: application/json' \ |
| 868 | -d '{ | 874 | -d '{ |
| @@ -875,7 +881,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X POST \ | @@ -875,7 +881,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X POST \ | ||
| 875 | } | 881 | } |
| 876 | }' | 882 | }' |
| 877 | 883 | ||
| 878 | -curl -u 'saas:4hOaLaf41y2VuI8y' -X POST \ | 884 | +curl -u "$ES_AUTH" -X POST \ |
| 879 | 'http://localhost:9200/search_products_tenant_163/_count' \ | 885 | 'http://localhost:9200/search_products_tenant_163/_count' \ |
| 880 | -H 'Content-Type: application/json' \ | 886 | -H 'Content-Type: application/json' \ |
| 881 | -d '{ | 887 | -d '{ |