繁体   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

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": {
        "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 :成功将新文档添加到索引menu

Procedure

我正在尝试使用elastic search批量插入。 我已经参考了文档,这是他们在下面提供的示例。

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

我以相同的方式建立了我的格式,但我不断收到错误。 这就是我的body进入postman的样子。

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

我在这里做错了什么?

您的 Json 格式确实不正确。 Postman 主体部分将显示给定 Json 的错误。 此外,批量请求正文并不意味着在单个有效的 Json 中。

使用与 curl 相同的数据,结果会成功。

此外,当使用 POSTMAN 的命令数据时,每个“节”应该在一行内(即每一行代表一个有效的 json)。 此外,不应有空行。 (这里与“bcp”命令有一些相似之处)

所以,这会工作

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

但这不适用于批量插入的 postman

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

“您的 json 格式不正确。您可以复制代码并检查”定期访问http://json.parser.online.fr/

似乎正文的格式不正确。 发布以下内容后,我能够成功发布到 elasticsearch。 需要注意的一点是,在 postman 中,您必须拥有它,以便每条线都尽可能靠近。 我的意思是在新行的末尾你的身体之间必须没有间距。

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