有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java意外endofinput:数组ElasticSearch需要关闭标记

我正在创建对弹性搜索的批量请求,但得到了标题中指定的错误 有人能查一下我的JSON吗也许这不对

{ "index" :{ "_index" : "type", "_type" : "type", "_id" : "1" }}
{"type": "Variable", "processDefinitionKey":"Variable1", "products":[
{ "index" :{ "_index" : "new_type", "_type" : "new_type", "_id" : "1" }}
{ "code": "20", "type": "Variable", "name": "Integer"}]}

共 (1) 个答案

  1. # 1 楼答案

    实际上,问题是文档似乎被分成了第2行和第4行,而且两行都不完整

    { "index" :{ "_index" : "type", "_type" : "type", "_id" : "1" }}
    {"type": "Variable", "processDefinitionKey":"Variable1", "products":[
    { "index" :{ "_index" : "new_type", "_type" : "new_type", "_id" : "1" }}
    { "code": "20", "type": "Variable", "name": "Integer"}]}
    

    你的文件实际上是这样的

    {"type": "Variable", "processDefinitionKey":"Variable1", "products":[
    

    再加上这个

    { "code": "20", "type": "Variable", "name": "Integer"}]}
    

    但是它被分成两行,中间有index个命令。。。那不行

    它应该是这样的:

    { "index" :{ "_index" : "type", "_type" : "type", "_id" : "1" }}
    {"type": "Variable", "processDefinitionKey":"Variable1", "products":[{ "code": "20", "type": "Variable", "name": "Integer"}]}
    { "index" :{ "_index" : "new_type", "_type" : "new_type", "_id" : "1" }}
    {"type": "Variable", "processDefinitionKey":"Variable1", "products":[{ "code": "20", "type": "Variable", "name": "Integer"}]}
    

    你需要确保:

    • JSON文档位于一行(而不是多行)
    • 每个JSON文档都有相应的命令行
    • 最后一行以换行符结尾(由于格式原因,上面不可见)