Skip to content
鼓励作者:欢迎打赏犒劳

ES示例数据

mock数据

新建表

shell
PUT /product_item_v1
{
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 0,
    "index": {
      "refresh_interval": "1s"
    }
  },
  "mappings": {
    "dynamic": "strict",
    "properties": {
      "product_id": {
        "type": "keyword"
      },
      "product_name": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "description": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 512
          }
        }
      },
      "category": {
        "type": "keyword"
      },
      "tags": {
        "type": "keyword"
      },
      "price": {
        "type": "double"
      },
      "original_price": {
        "type": "double"
      },
      "discount_rate": {
        "type": "float"
      },
      "stock_quantity": {
        "type": "integer"
      },
      "weight_kg": {
        "type": "float"
      },
      "is_active": {
        "type": "boolean"
      },
      "is_prime": {
        "type": "boolean"
      },
      "rating": {
        "type": "float"
      },
      "review_count": {
        "type": "integer"
      },
      "sales_volume": {
        "type": "integer"
      },
      "create_time": {
        "type": "date",
        "format": "yyyy-MM-dd'T'HH:mm:ss"
      },
      "update_time": {
        "type": "date",
        "format": "yyyy-MM-dd'T'HH:mm:ss"
      },
      "shelf_life_days": {
        "type": "integer"
      },
      "delivery_timeout_hours": {
        "type": "integer"
      },
      "supplier_info": {
        "type": "object",
        "properties": {
          "supplier_id": {
            "type": "keyword"
          },
          "supplier_name": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 128
              }
            }
          },
          "supplier_phone": {
            "type": "keyword"
          },
          "supplier_rating": {
            "type": "float"
          },
          "warehouse_location": {
            "type": "keyword"
          }
        }
      },
      "specs": {
        "type": "nested",
        "properties": {
          "spec_name": {
            "type": "keyword"
          },
          "spec_value": {
            "type": "keyword"
          },
          "spec_unit": {
            "type": "keyword"
          }
        }
      },
      "images": {
        "type": "keyword"
      },
      "sales_region": {
        "type": "keyword"
      },
      "vip_only": {
        "type": "boolean"
      },
      "priority": {
        "type": "integer"
      },
      "color_options": {
        "type": "keyword"
      },
      "size_options": {
        "type": "keyword"
      },
      "related_product_ids": {
        "type": "integer"
      },
      "monthly_sales": {
        "type": "integer"
      },
      "profit_margin": {
        "type": "float"
      },
      "dimensions": {
        "type": "object",
        "properties": {
          "length_cm": {
            "type": "float"
          },
          "width_cm": {
            "type": "float"
          },
          "height_cm": {
            "type": "float"
          }
        }
      },
      "warranty_months": {
        "type": "integer"
      }
    }
  },
  "aliases": {
    "product_item": {}
  }
}

插入数据

shell
POST /product_item_v1/_bulk
{"index": {}}
{"product_id":"P10001","product_name":"Apple iPhone 15 Pro Max","description":"6.7英寸 OLED 显示屏,A17 Pro 芯片,钛金属边框","category":"Electronics","tags":["smartphone","apple","5g"],"price":1199.99,"original_price":1299.99,"discount_rate":0.077,"stock_quantity":245,"weight_kg":0.221,"is_active":true,"is_prime":true,"rating":4.8,"review_count":3250,"sales_volume":15230,"create_time":"2026-01-15T10:30:00","update_time":"2026-07-14T08:20:00","shelf_life_days":null,"delivery_timeout_hours":24,"supplier_info":{"supplier_id":"S001","supplier_name":"Apple Premium Distributor","supplier_phone":"+86-400-888-9999","supplier_rating":4.9,"warehouse_location":"Shanghai, China"},"specs":[{"spec_name":"Color","spec_value":"Natural Titanium","spec_unit":null},{"spec_name":"Storage","spec_value":"256GB","spec_unit":null},{"spec_name":"RAM","spec_value":"8GB","spec_unit":null}],"images":["https://img.example.com/p10001_1.jpg","https://img.example.com/p10001_2.jpg"],"sales_region":["North America","Europe","Asia"],"vip_only":false,"priority":10,"color_options":["Natural Titanium","Blue Titanium","White Titanium","Black Titanium"],"size_options":[],"related_product_ids":[10002,10003,10004],"monthly_sales":1890,"profit_margin":0.35,"dimensions":{"length_cm":16.07,"width_cm":7.76,"height_cm":0.83},"warranty_months":12}
{"index": {}}
{"product_id":"P10002","product_name":"Sony WH-1000XM5 Wireless Headphones","description":"旗舰级降噪耳机,30小时续航,LDAC高清音频","category":"Electronics","tags":["headphones","sony","noise-cancelling"],"price":399.99,"original_price":449.99,"discount_rate":0.111,"stock_quantity":189,"weight_kg":0.25,"is_active":true,"is_prime":true,"rating":4.7,"review_count":1850,"sales_volume":8760,"create_time":"2026-02-01T14:20:00","update_time":"2026-07-13T16:45:00","shelf_life_days":null,"delivery_timeout_hours":48,"supplier_info":{"supplier_id":"S002","supplier_name":"Sony Audio Solutions","supplier_phone":"+86-400-810-0000","supplier_rating":4.8,"warehouse_location":"Shenzhen, China"},"specs":[{"spec_name":"Color","spec_value":"Black","spec_unit":null},{"spec_name":"Battery Life","spec_value":"30","spec_unit":"hours"}],"images":["https://img.example.com/p10002_1.jpg"],"sales_region":["Global"],"vip_only":false,"priority":8,"color_options":["Black","Silver"],"size_options":[],"related_product_ids":[10005,10006],"monthly_sales":950,"profit_margin":0.28,"dimensions":{"length_cm":18.5,"width_cm":17.2,"height_cm":7.4},"warranty_months":18}
{"index": {}}
{"product_id":"P10003","product_name":"Nordic Naturals Omega-3 Fish Oil","description":"高浓度 EPA/DHA 鱼油,支持心脏和大脑健康","category":"Health","tags":["supplement","omega3","fish-oil"],"price":56.95,"original_price":69.95,"discount_rate":0.186,"stock_quantity":520,"weight_kg":0.34,"is_active":true,"is_prime":true,"rating":4.9,"review_count":4200,"sales_volume":23450,"create_time":"2026-03-10T09:00:00","update_time":"2026-07-14T07:30:00","shelf_life_days":730,"delivery_timeout_hours":72,"supplier_info":{"supplier_id":"S003","supplier_name":"Nordic Naturals China","supplier_phone":"+86-400-686-8888","supplier_rating":4.9,"warehouse_location":"Qingdao, China"},"specs":[{"spec_name":"Size","spec_value":"180","spec_unit":"Softgels"},{"spec_name":"Strength","spec_value":"1280","spec_unit":"mg"}],"images":["https://img.example.com/p10003_1.jpg","https://img.example.com/p10003_2.jpg"],"sales_region":["North America","Europe","Asia"],"vip_only":false,"priority":7,"color_options":[],"size_options":[],"related_product_ids":[10007,10008],"monthly_sales":2100,"profit_margin":0.42,"dimensions":{"length_cm":12.0,"width_cm":6.5,"height_cm":6.5},"warranty_months":null}
{"index": {}}
{"product_id":"P10004","product_name":"Dyson V15 Detect Cordless Vacuum","description":"激光探测灰尘,智能吸力调节,续航60分钟","category":"Home & Kitchen","tags":["vacuum","dyson","cordless"],"price":749.99,"original_price":799.99,"discount_rate":0.063,"stock_quantity":78,"weight_kg":3.1,"is_active":true,"is_prime":true,"rating":4.6,"review_count":980,"sales_volume":4530,"create_time":"2026-01-20T11:15:00","update_time":"2026-07-12T13:10:00","shelf_life_days":null,"delivery_timeout_hours":48,"supplier_info":{"supplier_id":"S004","supplier_name":"Dyson Official Store","supplier_phone":"+86-400-820-7890","supplier_rating":4.7,"warehouse_location":"Suzhou, China"},"specs":[{"spec_name":"Color","spec_value":"Yellow","spec_unit":null},{"spec_name":"Battery Life","spec_value":"60","spec_unit":"minutes"}],"images":["https://img.example.com/p10004_1.jpg"],"sales_region":["North America","Europe"],"vip_only":false,"priority":9,"color_options":["Yellow","Blue"],"size_options":[],"related_product_ids":[10009,10010],"monthly_sales":380,"profit_margin":0.22,"dimensions":{"length_cm":126.0,"width_cm":25.0,"height_cm":26.0},"warranty_months":24}
{"index": {}}
{"product_id":"P10005","product_name":"Levi's 511 Slim Fit Jeans","description":"经典修身牛仔裤,99%棉,舒适有弹性","category":"Clothing","tags":["jeans","levis","slim-fit"],"price":89.99,"original_price":89.99,"discount_rate":0.0,"stock_quantity":430,"weight_kg":0.52,"is_active":true,"is_prime":false,"rating":4.4,"review_count":2150,"sales_volume":18200,"create_time":"2026-04-05T16:40:00","update_time":"2026-07-10T09:55:00","shelf_life_days":null,"delivery_timeout_hours":72,"supplier_info":{"supplier_id":"S005","supplier_name":"Levi's Retail China","supplier_phone":"+86-400-889-6600","supplier_rating":4.5,"warehouse_location":"Guangzhou, China"},"specs":[{"spec_name":"Color","spec_value":"Blue","spec_unit":null},{"spec_name":"Waist","spec_value":"32","spec_unit":"inches"},{"spec_name":"Length","spec_value":"34","spec_unit":"inches"}],"images":["https://img.example.com/p10005_1.jpg","https://img.example.com/p10005_2.jpg"],"sales_region":["North America","Europe","Asia"],"vip_only":false,"priority":5,"color_options":["Blue","Black","Grey"],"size_options":["28x30","29x30","30x30","30x32","31x32","32x32","32x34","33x34","34x34"],"related_product_ids":[10011,10012],"monthly_sales":1520,"profit_margin":0.45,"dimensions":{"length_cm":35.0,"width_cm":25.0,"height_cm":2.0},"warranty_months":6}
{"index": {}}
{"product_id":"P10006","product_name":"Samsung 990 PRO 2TB NVMe SSD","description":"PCIe 4.0,读取速度7450 MB/s,高性能存储","category":"Electronics","tags":["ssd","samsung","storage"],"price":189.99,"original_price":229.99,"discount_rate":0.174,"stock_quantity":312,"weight_kg":0.03,"is_active":true,"is_prime":true,"rating":4.8,"review_count":3200,"sales_volume":15680,"create_time":"2026-02-15T08:30:00","update_time":"2026-07-14T10:00:00","shelf_life_days":null,"delivery_timeout_hours":24,"supplier_info":{"supplier_id":"S006","supplier_name":"Samsung Storage Solutions","supplier_phone":"+86-400-810-5858","supplier_rating":4.8,"warehouse_location":"Xi'an, China"},"specs":[{"spec_name":"Capacity","spec_value":"2TB","spec_unit":null},{"spec_name":"Interface","spec_value":"NVMe PCIe 4.0","spec_unit":null}],"images":["https://img.example.com/p10006_1.jpg"],"sales_region":["Global"],"vip_only":false,"priority":8,"color_options":[],"size_options":[],"related_product_ids":[10013,10014],"monthly_sales":1340,"profit_margin":0.25,"dimensions":{"length_cm":8.0,"width_cm":2.2,"height_cm":0.23},"warranty_months":60}
{"index": {}}
{"product_id":"P10007","product_name":"Lululemon Align High-Rise Pant 28\"","description":"Nulu面料,高腰设计,瑜伽裤,舒适支撑","category":"Clothing","tags":["yoga","lululemon","athleisure"],"price":118.00,"original_price":118.00,"discount_rate":0.0,"stock_quantity":195,"weight_kg":0.28,"is_active":true,"is_prime":false,"rating":4.9,"review_count":5600,"sales_volume":32100,"create_time":"2026-03-20T13:25:00","update_time":"2026-07-13T11:40:00","shelf_life_days":null,"delivery_timeout_hours":48,"supplier_info":{"supplier_id":"S007","supplier_name":"Lululemon Athletica Asia","supplier_phone":"+86-400-820-1234","supplier_rating":4.9,"warehouse_location":"Shanghai, China"},"specs":[{"spec_name":"Color","spec_value":"Black","spec_unit":null},{"spec_name":"Size","spec_value":"6","spec_unit":null},{"spec_name":"Length","spec_value":"28","spec_unit":"inches"}],"images":["https://img.example.com/p10007_1.jpg","https://img.example.com/p10007_2.jpg"],"sales_region":["North America","Europe","Asia"],"vip_only":false,"priority":6,"color_options":["Black","Navy","Olive","Grey Sage"],"size_options":["2","4","6","8","10","12"],"related_product_ids":[10015,10016],"monthly_sales":2680,"profit_margin":0.50,"dimensions":{"length_cm":30.0,"width_cm":20.0,"height_cm":3.0},"warranty_months":12}
{"index": {}}
{"product_id":"P10008","product_name":"Philips 3200 Series Fully Automatic Espresso Machine","description":"LatteGo奶泡系统,一键制作多种咖啡饮品","category":"Home & Kitchen","tags":["coffee","philips","espresso"],"price":799.00,"original_price":899.00,"discount_rate":0.111,"stock_quantity":64,"weight_kg":7.2,"is_active":true,"is_prime":true,"rating":4.7,"review_count":750,"sales_volume":3420,"create_time":"2026-01-08T07:50:00","update_time":"2026-07-11T14:30:00","shelf_life_days":null,"delivery_timeout_hours":48,"supplier_info":{"supplier_id":"S008","supplier_name":"Philips Home Appliances","supplier_phone":"+86-400-880-0008","supplier_rating":4.6,"warehouse_location":"Ningbo, China"},"specs":[{"spec_name":"Color","spec_value":"Black","spec_unit":null},{"spec_name":"Power","spec_value":"1500","spec_unit":"W"},{"spec_name":"Water Tank","spec_value":"1.8","spec_unit":"L"}],"images":["https://img.example.com/p10008_1.jpg"],"sales_region":["Europe","North America","Asia"],"vip_only":false,"priority":7,"color_options":["Black","White"],"size_options":[],"related_product_ids":[10017,10018],"monthly_sales":285,"profit_margin":0.30,"dimensions":{"length_cm":43.0,"width_cm":25.5,"height_cm":33.0},"warranty_months":24}
{"index": {}}
{"product_id":"P10009","product_name":"The North Face Himalayan Suit Expedition Jacket","description":"专业级羽绒服,适合极端寒冷气候登山探险","category":"Outdoors","tags":["jacket","north-face","expedition"],"price":899.99,"original_price":999.99,"discount_rate":0.10,"stock_quantity":42,"weight_kg":2.8,"is_active":true,"is_prime":false,"rating":4.8,"review_count":430,"sales_volume":1890,"create_time":"2026-05-01T10:00:00","update_time":"2026-07-12T08:15:00","shelf_life_days":null,"delivery_timeout_hours":72,"supplier_info":{"supplier_id":"S009","supplier_name":"The North Face China","supplier_phone":"+86-400-882-8888","supplier_rating":4.7,"warehouse_location":"Chengdu, China"},"specs":[{"spec_name":"Color","spec_value":"Yellow","spec_unit":null},{"spec_name":"Size","spec_value":"L","spec_unit":null},{"spec_name":"Fill Power","spec_value":"800","spec_unit":"FP"}],"images":["https://img.example.com/p10009_1.jpg","https://img.example.com/p10009_2.jpg"],"sales_region":["North America","Europe"],"vip_only":true,"priority":10,"color_options":["Yellow","Red","Navy"],"size_options":["S","M","L","XL","XXL"],"related_product_ids":[10019,10020],"monthly_sales":158,"profit_margin":0.32,"dimensions":{"length_cm":65.0,"width_cm":45.0,"height_cm":12.0},"warranty_months":36}
{"index": {}}
{"product_id":"P10010","product_name":"LEGO Star Wars Millennium Falcon 75192","description":"终极收藏系列,7541块积木,长达84厘米","category":"Toys","tags":["lego","star-wars","collectible"],"price":849.99,"original_price":849.99,"discount_rate":0.0,"stock_quantity":28,"weight_kg":12.5,"is_active":true,"is_prime":true,"rating":4.9,"review_count":3200,"sales_volume":8900,"create_time":"2026-06-15T18:30:00","update_time":"2026-07-14T06:00:00","shelf_life_days":null,"delivery_timeout_hours":72,"supplier_info":{"supplier_id":"S010","supplier_name":"LEGO Certified Store","supplier_phone":"+86-400-800-8888","supplier_rating":4.9,"warehouse_location":"Shanghai, China"},"specs":[{"spec_name":"Pieces","spec_value":"7541","spec_unit":null},{"spec_name":"Age","spec_value":"16","spec_unit":"years+"}],"images":["https://img.example.com/p10010_1.jpg","https://img.example.com/p10010_2.jpg","https://img.example.com/p10010_3.jpg"],"sales_region":["Global"],"vip_only":false,"priority":9,"color_options":[],"size_options":[],"related_product_ids":[10021,10022,10023],"monthly_sales":740,"profit_margin":0.18,"dimensions":{"length_cm":84.0,"width_cm":56.0,"height_cm":21.0},"warranty_months":null}

字段类型描述与典型查询场景

一、基础信息字段

字段类型描述典型查询场景
product_idkeyword商品唯一ID(如:P10001)精确匹配查询、批量ID查询 terms、聚合统计
product_nametext + keyword商品名称(支持全文搜索 + 精确匹配)名称模糊搜索 match、品牌名精确筛选 term
descriptiontext + keyword商品详细描述(支持全文搜索 + 精确匹配)描述关键词检索 match_phrase、长描述精确匹配
categorykeyword商品类目(如:Electronics)类目筛选 term、类目聚合统计 terms
tagskeyword (数组)商品标签(如:["smartphone", "5g"])标签筛选 terms、标签聚合统计、交集查询

二、价格与折扣字段

字段类型描述典型查询场景
pricedouble当前售价(支持高精度价格)价格范围筛选 range、排序、均价聚合
original_pricedouble原价/划线价(支持高精度)价格对比、折扣计算、历史价格分析
discount_ratefloat折扣率(0~1之间)筛选打折商品 range、按折扣力度排序

三、库存与物流字段

字段类型描述典型查询场景
stock_quantityinteger库存数量库存预警筛选(<=阈值)、有货/缺货判断
weight_kgfloat商品重量(千克)运费计算筛选、按重量范围筛选
shelf_life_daysinteger保质期(天数),食品类用临期商品筛选、保质期排序
delivery_timeout_hoursinteger承诺发货时效(小时)筛选快速发货商品、按时效排序

四、状态与评分字段

字段类型描述典型查询场景
is_activeboolean是否上架筛选在售商品(最常用过滤器)
is_primeboolean是否Prime会员专享会员特权商品筛选
vip_onlyboolean是否仅VIP可购买VIP专属商品筛选
ratingfloat平均评分(1~5分)高分商品筛选 range、按评分排序
review_countinteger评价总数热门商品筛选(高评价数)、排序因子
sales_volumeinteger销量总数畅销商品筛选、按销量排序
monthly_salesinteger月销量月度热榜、趋势分析
priorityinteger推荐优先级(越高越靠前)自定义排序、加权召回

五、时间字段

字段类型描述典型查询场景
create_timedate创建时间新品筛选(最近创建)、按时间排序
update_timedate更新时间近期更新商品、价格变动追踪

六、供应商信息(object)

字段类型描述典型查询场景
supplier_info.supplier_idkeyword供应商ID按供应商筛选商品
supplier_info.supplier_nametext + keyword供应商名称供应商名称搜索、精确匹配
supplier_info.supplier_phonekeyword供应商电话精确查询、内部管理查询
supplier_info.supplier_ratingfloat供应商评分筛选高信誉供应商商品
supplier_info.warehouse_locationkeyword仓库位置(城市/区域)按发货地筛选、同城发货

七、规格参数(nested)

字段类型描述典型查询场景
specs.spec_namekeyword规格名称(如:Color, Storage)规格名筛选
specs.spec_valuekeyword规格值(如:256GB, Black)按规格值筛选商品(nested查询)
specs.spec_unitkeyword规格单位(如:GB, cm)单位筛选、展示用

⚠️ 注意specsnested 类型,查询时必须使用 nested 查询语法,确保每个规格属性对独立匹配。

八、多媒体与扩展字段

字段类型描述典型查询场景
imageskeyword (数组)商品图片URL列表展示用,较少用于查询
sales_regionkeyword (数组)销售区域(如:["North America", "Asia"])区域可用性筛选
color_optionskeyword (数组)可选颜色列表(如:["Black", "White"])按颜色筛选商品
size_optionskeyword (数组)可选尺码列表(如:["S","M","L"])按尺码筛选商品
related_product_idsinteger (数组)关联推荐商品ID列表推荐逻辑、关联查询

九、额外属性字段

字段类型描述典型查询场景
profit_marginfloat利润率(0~1之间)财务分析、品类盈利分析
warranty_monthsinteger保修月数筛选保修期长的商品
dimensions.length_cmfloat长度(厘米)按尺寸筛选(如:小件/大件)
dimensions.width_cmfloat宽度(厘米)按尺寸筛选
dimensions.height_cmfloat高度(厘米)按尺寸筛选、体积计算

典型组合查询场景示例

1. 商品列表筛选(电商核心查询)

json
{
  "query": {
    "bool": {
      "filter": [
        { "term": { "is_active": true } },
        { "term": { "category": "Electronics" } },
        { "range": { "price": { "gte": 100, "lte": 500 } } },
        { "terms": { "tags": ["smartphone", "5g"] } }
      ],
      "must": [
        { "match": { "product_name": "iPhone" } }
      ]
    }
  },
  "sort": [
    { "rating": "desc" },
    { "sales_volume": "desc" }
  ]
}

2. 规格筛选(nested查询)

json
{
  "query": {
    "nested": {
      "path": "specs",
      "query": {
        "bool": {
          "must": [
            { "term": { "specs.spec_name": "Storage" } },
            { "term": { "specs.spec_value": "256GB" } }
          ]
        }
      }
    }
  }
}

3. 多条件过滤 + 聚合统计

json
{
  "query": {
    "bool": {
      "filter": [
        { "term": { "is_active": true } },
        { "term": { "is_prime": true } },
        { "range": { "rating": { "gte": 4.5 } } }
      ]
    }
  },
  "aggs": {
    "by_category": {
      "terms": { "field": "category", "size": 10 }
    },
    "avg_price": {
      "avg": { "field": "price" }
    }
  }
}

4. 搜索建议/自动补全(利用keyword子字段)

json
{
  "query": {
    "prefix": { "product_name.keyword": "iPhone" }
  }
}

5. 库存预警查询

json
{
  "query": {
    "bool": {
      "filter": [
        { "term": { "is_active": true } },
        { "range": { "stock_quantity": { "lte": 50 } } }
      ]
    }
  },
  "sort": [{ "stock_quantity": "asc" }]
}

6. 供应商+区域复合筛选

json
{
  "query": {
    "bool": {
      "filter": [
        { "term": { "supplier_info.supplier_id": "S001" } },
        { "terms": { "sales_region": ["Asia", "Europe"] } }
      ]
    }
  }
}

7. 价格与尺寸综合排序(大件商品价格排序)

json
{
  "query": {
    "bool": {
      "filter": [
        { "term": { "is_active": true } },
        { "range": { "dimensions.length_cm": { "gte": 50 } } }
      ]
    }
  },
  "sort": [
    { "price": "asc" },
    { "priority": "desc" }
  ]
}

如有转载或 CV 的请标注本站原文地址