Commit f27a8d90508eae062e79cf4d73abbf7a7bf6fb98
1 parent
8e081187
ES文档维护
Showing
3 changed files
with
49 additions
and
41 deletions
Show diff stats
.env.example
docs/常用查询 - ES.md
| 1 | - | |
| 2 | - | |
| 3 | 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 | 11 | ### 1. 集群健康状态 |
| 6 | 12 | |
| 7 | 13 | ```bash |
| 8 | 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 | 18 | ### 2. 索引概览 |
| 13 | 19 | |
| 14 | 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 | 28 | ### 3. 分片分布 |
| 23 | 29 | |
| 24 | 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 | 35 | ### 4. 分配诊断(如有异常) |
| 30 | 36 | |
| 31 | 37 | ```bash |
| 32 | 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 | 40 | -H 'Content-Type: application/json' \ |
| 35 | 41 | -d '{"index":"search_products_tenant_163","shard":0,"primary":true}' |
| 36 | 42 | ``` |
| ... | ... | @@ -69,7 +75,7 @@ journalctl -u elasticsearch -f |
| 69 | 75 | ```bash |
| 70 | 76 | # 按需替换:索引名、账号密码、ES 地址 |
| 71 | 77 | INDEX="search_products_tenant_163" |
| 72 | -AUTH='saas:4hOaLaf41y2VuI8y' | |
| 78 | +AUTH="$ES_AUTH" | |
| 73 | 79 | ES="http://localhost:9200" |
| 74 | 80 | |
| 75 | 81 | # 1) 关闭索引(写入类请求会失败,注意维护窗口) |
| ... | ... | @@ -141,7 +147,7 @@ systemctl / df / 日志 → 系统层验证 |
| 141 | 147 | |
| 142 | 148 | #### 查询指定 spu_id 的商品(返回 title) |
| 143 | 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 | 151 | "size": 11, |
| 146 | 152 | "_source": ["title"], |
| 147 | 153 | "query": { |
| ... | ... | @@ -156,7 +162,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te |
| 156 | 162 | |
| 157 | 163 | #### 查询所有商品(返回 title) |
| 158 | 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 | 166 | "size": 100, |
| 161 | 167 | "_source": ["title"], |
| 162 | 168 | "query": { |
| ... | ... | @@ -167,7 +173,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te |
| 167 | 173 | |
| 168 | 174 | #### 查询指定 spu_id 的商品(返回 title、keywords、tags) |
| 169 | 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 | 177 | "size": 5, |
| 172 | 178 | "_source": ["title", "keywords", "tags"], |
| 173 | 179 | "query": { |
| ... | ... | @@ -182,7 +188,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te |
| 182 | 188 | |
| 183 | 189 | #### 组合查询:匹配标题 + 过滤标签 |
| 184 | 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 | 192 | "size": 1, |
| 187 | 193 | "_source": ["title", "keywords", "tags"], |
| 188 | 194 | "query": { |
| ... | ... | @@ -206,7 +212,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te |
| 206 | 212 | |
| 207 | 213 | #### 组合查询:匹配标题 + 过滤租户(冗余示例) |
| 208 | 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 | 216 | "size": 1, |
| 211 | 217 | "_source": ["title"], |
| 212 | 218 | "query": { |
| ... | ... | @@ -234,7 +240,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te |
| 234 | 240 | |
| 235 | 241 | #### 测试 index_ik 分析器 |
| 236 | 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 | 244 | "analyzer": "index_ik", |
| 239 | 245 | "text": "14寸第4代-眼珠实身冰雪公仔带手动大推车,搪胶雪宝宝" |
| 240 | 246 | }' |
| ... | ... | @@ -242,7 +248,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te |
| 242 | 248 | |
| 243 | 249 | #### 测试 query_ik 分析器 |
| 244 | 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 | 252 | "analyzer": "query_ik", |
| 247 | 253 | "text": "14寸第4代-眼珠实身冰雪公仔带手动大推车,搪胶雪宝宝" |
| 248 | 254 | }' |
| ... | ... | @@ -254,7 +260,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te |
| 254 | 260 | |
| 255 | 261 | #### 多字段匹配 + 聚合(category1、color、size、material) |
| 256 | 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 | 264 | "size": 1, |
| 259 | 265 | "from": 0, |
| 260 | 266 | "query": { |
| ... | ... | @@ -364,7 +370,7 @@ GET /search_products_tenant_2/_search |
| 364 | 370 | |
| 365 | 371 | #### 按 spu_id 查询(通用索引) |
| 366 | 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 | 374 | "size": 5, |
| 369 | 375 | "query": { |
| 370 | 376 | "bool": { |
| ... | ... | @@ -381,7 +387,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products/_s |
| 381 | 387 | ### 5. 统计租户总文档数 |
| 382 | 388 | |
| 383 | 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 | 391 | "query": { |
| 386 | 392 | "match_all": {} |
| 387 | 393 | } |
| ... | ... | @@ -396,7 +402,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te |
| 396 | 402 | |
| 397 | 403 | #### 1.1 查询特定租户的商品,显示分面相关字段 |
| 398 | 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 | 406 | "query": { |
| 401 | 407 | "term": { "tenant_id": "162" } |
| 402 | 408 | }, |
| ... | ... | @@ -411,7 +417,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te |
| 411 | 417 | |
| 412 | 418 | #### 1.2 验证 category1_name 字段是否有数据 |
| 413 | 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 | 421 | "query": { |
| 416 | 422 | "bool": { |
| 417 | 423 | "filter": [ |
| ... | ... | @@ -426,7 +432,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te |
| 426 | 432 | |
| 427 | 433 | #### 1.3 验证 specifications 字段是否有数据 |
| 428 | 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 | 436 | "query": { |
| 431 | 437 | "bool": { |
| 432 | 438 | "filter": [ |
| ... | ... | @@ -445,7 +451,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te |
| 445 | 451 | |
| 446 | 452 | #### 2.1 category1_name 分面聚合 |
| 447 | 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 | 455 | "query": { "match_all": {} }, |
| 450 | 456 | "size": 0, |
| 451 | 457 | "aggs": { |
| ... | ... | @@ -458,7 +464,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te |
| 458 | 464 | |
| 459 | 465 | #### 2.2 specifications.color 分面聚合 |
| 460 | 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 | 468 | "query": { "match_all": {} }, |
| 463 | 469 | "size": 0, |
| 464 | 470 | "aggs": { |
| ... | ... | @@ -479,7 +485,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te |
| 479 | 485 | |
| 480 | 486 | #### 2.3 specifications.size 分面聚合 |
| 481 | 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 | 489 | "query": { "match_all": {} }, |
| 484 | 490 | "size": 0, |
| 485 | 491 | "aggs": { |
| ... | ... | @@ -500,7 +506,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te |
| 500 | 506 | |
| 501 | 507 | #### 2.4 specifications.material 分面聚合 |
| 502 | 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 | 510 | "query": { "match_all": {} }, |
| 505 | 511 | "size": 0, |
| 506 | 512 | "aggs": { |
| ... | ... | @@ -521,7 +527,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te |
| 521 | 527 | |
| 522 | 528 | #### 2.5 综合分面聚合(category + color + size + material) |
| 523 | 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 | 531 | "query": { "match_all": {} }, |
| 526 | 532 | "size": 0, |
| 527 | 533 | "aggs": { |
| ... | ... | @@ -563,7 +569,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te |
| 563 | 569 | |
| 564 | 570 | #### 3.1 查看 specifications 的 name 字段有哪些值 |
| 565 | 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 | 573 | "query": { "term": { "tenant_id": "162" } }, |
| 568 | 574 | "size": 0, |
| 569 | 575 | "aggs": { |
| ... | ... | @@ -579,7 +585,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products/_s |
| 579 | 585 | |
| 580 | 586 | #### 3.2 查看某个商品的完整 specifications 数据 |
| 581 | 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 | 589 | "query": { |
| 584 | 590 | "bool": { |
| 585 | 591 | "filter": [ |
| ... | ... | @@ -600,7 +606,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products/_s |
| 600 | 606 | **keyword 精确匹配**(示例词:中文 `法式风格`,英文 `long skirt`) |
| 601 | 607 | |
| 602 | 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 | 610 | "size": 1, |
| 605 | 611 | "_source": ["spu_id", "title", "enriched_attributes"], |
| 606 | 612 | "query": { |
| ... | ... | @@ -623,7 +629,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te |
| 623 | 629 | **text 全文匹配**(经 `index_ik` / `english` 分词;可与上式对照) |
| 624 | 630 | |
| 625 | 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 | 633 | "size": 1, |
| 628 | 634 | "_source": ["spu_id", "title", "enriched_attributes"], |
| 629 | 635 | "query": { |
| ... | ... | @@ -650,7 +656,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te |
| 650 | 656 | **keyword 精确匹配** |
| 651 | 657 | |
| 652 | 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 | 660 | "size": 1, |
| 655 | 661 | "_source": ["spu_id", "title", "option1_values"], |
| 656 | 662 | "query": { |
| ... | ... | @@ -668,7 +674,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te |
| 668 | 674 | **text 全文匹配** |
| 669 | 675 | |
| 670 | 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 | 678 | "size": 1, |
| 673 | 679 | "_source": ["spu_id", "title", "option1_values"], |
| 674 | 680 | "query": { |
| ... | ... | @@ -688,7 +694,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te |
| 688 | 694 | **keyword 精确匹配** |
| 689 | 695 | |
| 690 | 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 | 698 | "size": 1, |
| 693 | 699 | "_source": ["spu_id", "title", "enriched_tags"], |
| 694 | 700 | "query": { |
| ... | ... | @@ -706,7 +712,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te |
| 706 | 712 | **text 全文匹配** |
| 707 | 713 | |
| 708 | 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 | 716 | "size": 1, |
| 711 | 717 | "_source": ["spu_id", "title", "enriched_tags"], |
| 712 | 718 | "query": { |
| ... | ... | @@ -726,7 +732,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te |
| 726 | 732 | > `specifications` 为 **nested**,`value_keyword` 为整词匹配;`value_text.*` 可同时 `term` 子字段或 `match` 主 text。 |
| 727 | 733 | |
| 728 | 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 | 736 | "size": 1, |
| 731 | 737 | "_source": ["spu_id", "title", "specifications"], |
| 732 | 738 | "query": { |
| ... | ... | @@ -758,7 +764,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te |
| 758 | 764 | |
| 759 | 765 | #### 4.1 统计有 category1_name 的文档数量 |
| 760 | 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 | 768 | "query": { |
| 763 | 769 | "bool": { |
| 764 | 770 | "filter": [ |
| ... | ... | @@ -771,7 +777,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te |
| 771 | 777 | |
| 772 | 778 | #### 4.2 统计有 specifications 的文档数量 |
| 773 | 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 | 781 | "query": { |
| 776 | 782 | "bool": { |
| 777 | 783 | "filter": [ |
| ... | ... | @@ -788,7 +794,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te |
| 788 | 794 | |
| 789 | 795 | #### 5.1 查找没有 category1_name 但有 category 的文档(MySQL 有数据但 ES 没有) |
| 790 | 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 | 798 | "query": { |
| 793 | 799 | "bool": { |
| 794 | 800 | "filter": [ |
| ... | ... | @@ -806,7 +812,7 @@ curl -u 'saas:4hOaLaf41y2VuI8y' -X GET 'http://localhost:9200/search_products_te |
| 806 | 812 | |
| 807 | 813 | #### 5.2 查找有 option 但没有 specifications 的文档(数据转换问题) |
| 808 | 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 | 816 | "query": { |
| 811 | 817 | "bool": { |
| 812 | 818 | "filter": [ |
| ... | ... | @@ -862,7 +868,7 @@ GET search_products_tenant_163/_mapping |
| 862 | 868 | GET search_products_tenant_163/_field_caps?fields=* |
| 863 | 869 | |
| 864 | 870 | ```bash |
| 865 | -curl -u 'saas:4hOaLaf41y2VuI8y' -X POST \ | |
| 871 | +curl -u "$ES_AUTH" -X POST \ | |
| 866 | 872 | 'http://localhost:9200/search_products_tenant_163/_count' \ |
| 867 | 873 | -H 'Content-Type: application/json' \ |
| 868 | 874 | -d '{ |
| ... | ... | @@ -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 | 885 | 'http://localhost:9200/search_products_tenant_163/_count' \ |
| 880 | 886 | -H 'Content-Type: application/json' \ |
| 881 | 887 | -d '{ | ... | ... |