我正在尝试使用POST请求批量导入localhost:9200/products/product/_bulk以下JSON:
[
{ "index": {"_index": "products", "_type": "product", "_id": 1} },
{ "title": "Product A","description": "Brand A - Product A - 1.5 kg","price": 3.49,"sku": "wi208564","supermarket": "AJ","categories": "Fruit AJ","product_type": "Sinaasappels - mandarijnen","brand": "Brand A\n"},
{ "index": {"_index": "products", "_type": "product", "_id": 2} },
{ "title": "Product B","description": "Brand B - Product B - 1 kg","price": 2.49,"sku": "wi308564","supermarket": "AJ","categories": "Fruit AJ","product_type": "Sinaasappels - mandarijnen","brand": "Brand B\n"},
{ "index": {"_index": "products", "_type": "product", "_id": 3} },
{ "title": "Product C","description": "Brand C - Product C - 2.5 kg","price": 4.49,"sku": "wi108564","supermarket": "AJ","categories": "Fruit AJ","product_type": "Sinaasappels - mandarijnen","brand": "Brand C\n"}
]
Run Code Online (Sandbox Code Playgroud)
我一直收到以下错误:
{
"error": "JsonParseException[Unexpected end-of-input: expected close marker for ARRAY (from [Source: [B@2c1e2b0e; line: 1, column: 0])\ at [Source: [B@2c1e2b0e; line: 1, column: 3]]",
"status": 500
}
Run Code Online (Sandbox Code Playgroud)
我试过改变JSON格式,但没有用.什么似乎出错了?
Fre*_*ung 26
您的格式不太正确:对于批量请求,单个项目由换行符(不是逗号)分隔,并且末尾没有方括号(即有效负载是一系列JSON文档,但整个有效负载本身不是一个有效的json文件)
你的数据应该是这样的
{ "index": {"_index": "products", "_type": "product", "_id": 1} }
{ "title": "Product A","description": "Brand A - Product A - 1.5 kg","price": 3.49,"sku": "wi208564","supermarket": "AJ","categories": "Fruit AJ","product_type": "Sinaasappels - mandarijnen","brand": "Brand A\n"}
{ "index": {"_index": "products", "_type": "product", "_id": 2} }
{ "title": "Product B","description": "Brand B - Product B - 1 kg","price": 2.49,"sku": "wi308564","supermarket": "AJ","categories": "Fruit AJ","product_type": "Sinaasappels - mandarijnen","brand": "Brand B\n"}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17486 次 |
| 最近记录: |