首页 > 解决方案 > 无法批量索引到弹性搜索

问题描述

我有 json 文件,如图所示,

{ "index": { "_index": "volvo", "_type": "user" }}
{"dn": " cn=s,o=VCC\n", "changetype": " add\n", "mail": " com\n", "surname": " s\n", "givenname": " s\n", "cn": " su2\n", "objectclass": [" inetOrgPerson\n", " srvprvUserAux\n", " organizationalPerson\n", " Person\n", " ndsLoginProperties\n", " Top\n", " srvprvEntityAux\n"]}
{ "index": { "_index": "volvo", "_type": "user" }}
{"dn": " cn=s1,o=VCC\n", "changetype": " add\n", "mail": " com\n", "surname": " sa\n", "givenname": " su\n", "cn": " s\n", "objectclass": [" inetOrgPerson\n", " srvprvUserAux\n", " organizationalPerson\n", " Person\n", " ndsLoginProperties\n", " Top\n", " srvprvEntityAux\n"]}

当我尝试将此批量索引到我的弹性搜索时,我收到以下错误,

{"error":{"root_cause":[{"type":"json_parse_exception","reason":"Unexpected character ('�' (code 65533 / 0xfffd)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@4914595e; line: 2, column: 2]"}],"type":"json_parse_exception","reason":"Unexpected character ('�' (code 65533 / 0xfffd)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@4914595e; line: 2, column: 2]"},"status":500}

你能弄清楚我的json有什么问题吗?

标签: jsonelasticsearch

解决方案


我在批量索引时收到了同样的错误,并通过更改文件编码解决了这个问题。使用 Notepad++ 我将文件编码从 UTF-8-BOM 更改为 UTF-8,并且能够完成批量索引操作。


推荐阅读