Elasticsearch 批量 API - 意外的输入结束 : expected close marker for ARRAY

标签 elasticsearch

我正在尝试使用以下 JSON 向 localhost:9200/products/product/_bulk 发送 POST 请求来批量导入:

[
  { "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"}
]

我不断收到以下错误:

{
"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
}

我试过更改 JSON 格式,但没有帮助。似乎出了什么问题?

最佳答案

您的格式不太正确:对于批量请求,各个项目由换行符(不是逗号)分隔并且末尾没有方括号(即有效负载是一系列 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"}

关于Elasticsearch 批量 API - 意外的输入结束 : expected close marker for ARRAY,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29457887/

相关文章:

elasticsearch - Docker/如何确定链接?

elasticsearch - ElasticSearch:在两个不同范围内搜索,每个范围具有不同的聚合

sorting - Elasticsearch 对字符串进行排序未返回预期结果

php - 如何在PHP的ElasticSearch查询中使用SQL AND条件?

docker - 在kubernetes中运行最新的Elasticsearch集群

elasticsearch - 在 Elasticsearch 中对类型为Ip的字段进行通配符查询

elasticsearch - 使用JestClient进行ElasticSearch查询似乎很慢

sql-server - Elasticsearch返回旧的SQL结果

Elasticsearch:无法连接到本地主机端口 9200 - 连接被拒绝

elasticsearch - 如何改善我在Elasticsearch中的搜索?