簡體   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