简体   繁体   English

批量插入的 json 结构无效

[英]json structure for bulk insert not valid

Elasticsearch version : 7.1
Postman version : 7.8.0

Elastic Search Url : http://localhost:9200/menu/_bulk Elastic Search Url : http://localhost:9200/menu/_bulk

mapping

 "mappings": {
            "properties": {
                "input": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                },
                "output": {
                    "properties": {
                        "category": {
                            "type": "text",
                            "fields": {
                                "keyword": {
                                    "type": "keyword",
                                    "ignore_above": 256
                                }
                            }
                        },
                        "item": {
                            "type": "text",
                            "fields": {
                                "keyword": {
                                    "type": "keyword",
                                    "ignore_above": 256
                                }
                            }
                        },
                        "items": {
                            "properties": {
                                "category": {
                                    "type": "text",
                                    "fields": {
                                        "keyword": {
                                            "type": "keyword",
                                            "ignore_above": 256
                                        }
                                    }
                                },
                                "item": {
                                    "type": "text",
                                    "fields": {
                                        "keyword": {
                                            "type": "keyword",
                                            "ignore_above": 256
                                        }
                                    }
                                },
                                "modifiers": {
                                    "type": "text",
                                    "fields": {
                                        "keyword": {
                                            "type": "keyword",
                                            "ignore_above": 256
                                        }
                                    }
                                }
                            }
                        },
                        "modifiers": {
                            "type": "text",
                            "fields": {
                                "keyword": {
                                    "type": "keyword",
                                    "ignore_above": 256
                                }
                            }
                        },
                        "quantity": {
                            "type": "long"
                        }
                    }
                }
            }
        }

Error I am receving:我收到的错误:

{
    "error": {
        "root_cause": [
            {
                "type": "illegal_argument_exception",
                "reason": "Malformed action/metadata line [3], expected START_OBJECT or END_OBJECT but found [VALUE_STRING]"
            }
        ],
        "type": "illegal_argument_exception",
        "reason": "Malformed action/metadata line [3], expected START_OBJECT or END_OBJECT but found [VALUE_STRING]"
    },
    "status": 400

Expected Result : Successfully adding new documents to index menu Expected Result :成功将新文档添加到索引menu

Procedure

I am trying to a bulk insert with elastic search .我正在尝试使用elastic search批量插入。 I have referred to the documentation and this is an example they provided below.我已经参考了文档,这是他们在下面提供的示例。

{ "index" : { "_index" : "testindex", "_type" : "somerandomtype", "_id" : "1" } }
{ "somefield" : "value1" }
{ "index" : { "_index" : "testindex", "_type" : "somerandomtype", "_id" : "2" } }
{ "somefield" : "hello hello hello" }

I have based my formatting in the same manner but I keep getting the error.我以相同的方式建立了我的格式,但我不断收到错误。 This is what my body looks like thats going into postman .这就是我的body进入postman的样子。

{"index": { "_index": "menu", "_type":"_doc" } }
{"input": "angus-burger", "output": {
"category": "Sides", "item": "Angus-Deluxe Burger", "modifiers": [], "quantity": 1} }

What am I doing wrong here?我在这里做错了什么?

Your Json format is indeed incorrect.您的 Json 格式确实不正确。 Postman body section will show error with given Json. Postman 主体部分将显示给定 Json 的错误。 Additionally Bulk request body is not meant to be in single valid Json.此外,批量请求正文并不意味着在单个有效的 Json 中。

Use the same data with curl, and result will be success.使用与 curl 相同的数据,结果会成功。

Moreover, when using the command data with POSTMAN, each 'section' should be within a single line (ie each line represents a single valid json).此外,当使用 POSTMAN 的命令数据时,每个“节”应该在一行内(即每一行代表一个有效的 json)。 Moreover, there should be no blank lines.此外,不应有空行。 (there are some similarities here to 'bcp' command) (这里与“bcp”命令有一些相似之处)

So, this would work所以,这会工作

 {"index": { "_index": "menu", "_type":"_doc" } }
 {"input": "angus-burger", "output": {"category": "Sides", "item": "Angus-Deluxe Burger", "modifiers": [], "quantity": 2} }

But this won't work in postman for bulk insert但这不适用于批量插入的 postman

{
    "index": {
        "_index": "menu",
        "_type": "_doc"
    }
}
{
    "input": "angus-burger",
    "output": {
        "category": "Sides",
        "item": "Angus-Deluxe Burger",
        "modifiers": [],
        "quantity": 2
    }
}

"your json format not correct.you can copy the code and check " Visit http://json.parser.online.fr/ regularly! “您的 json 格式不正确。您可以复制代码并检查”定期访问http://json.parser.online.fr/

It seems that the format of the body was incorrect.似乎正文的格式不正确。 After posting the below, I was able to successfully post to elasticsearch.发布以下内容后,我能够成功发布到 elasticsearch。 One thing to note is that in postman, you must have it so each line is as close to the other.需要注意的一点是,在 postman 中,您必须拥有它,以便每条线都尽可能靠近。 By that I mean you must have no spacing between your body at the end of a new line.我的意思是在新行的末尾你的身体之间必须没有间距。

{"index": { "_index": "menu", "_type":"_doc" } }
{"input": "angus-burger", "output": {"category": "Sides", "item": "Angus-Deluxe Burger", "modifiers": [], "quantity": 1} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM