json - "unknown key [_index] for create index"

标签 json elasticsearch postman

Elasticsearch version : 7.1
Postman version : 7.8.0

我的网址看起来像这样
http://localhost:9200/menu

我遇到的错误:
{
    "error": {
        "root_cause": [
            {
                "type": "parse_exception",
                "reason": "unknown key [index] for create index"
            }
        ],
        "type": "parse_exception",
        "reason": "unknown key [index] for create index"
    },
    "status": 400
}
Expected Result:成功将新文档输入 menu指数。

我已经被这个问题困扰了几个小时。我尝试了不同的东西,但没有一个有效。我想要做的插入 elastic search使用 postman .我已经定义了我的mappings如下所示。
  "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"
                        }
                    }
                }
            }
        }

我将以下 body 传递给 postman 。
{
"index": {
    "_index": "catalog", "_type":"_doc"
    }}
{"input": "roast beef", "output": {
"category": "Sides", "item": "Large Roast-Beef Sandwich",   "modifiers": ["LG"], "quantity": 1
    }
}
Update 1 : 把 body 改成下面这个。
{
    "index": {
        "_index": "catalog",
        "_type": "_doc"
    },
    "key":{
        "input": "roast beef",
        "output": {
            "category": "Sides",
            "item": "Large Roast-Beef Sandwich",
            "modifiers": [
                "LG"
            ],
            "quantity": 1
        }
    }
}

我现在收到错误
{
    "error": {
        "root_cause": [
            {
                "type": "parse_exception",
                "reason": "unknown key [index] for create index"
            }
        ],
        "type": "parse_exception",
        "reason": "unknown key [index] for create index"
    },
    "status": 400
}
Update 2:把 body 改成这个后
{       
        "_index": "catalog",
        "_type": "_doc",     
        "input": "roast beef",
        "output": {
            "category": "Sides",
            "item": "Large Roast-Beef Sandwich",
            "modifiers": [
                "LG"
            ],
            "quantity": 1
        }
}

我收到以下错误
{
    "error": {
        "root_cause": [
            {
                "type": "parse_exception",
                "reason": "unknown key [output] for create index"
            }
        ],
        "type": "parse_exception",
        "reason": "unknown key [output] for create index"
    },
    "status": 400
}

最佳答案

您发送的 json 正文格式不正确。括号没有按正确的顺序关闭,并且 body 缺少键名。下面是正确的json格式

{       
        "_index": "catalog",
        "_type": "_doc"     
        "input": "roast beef",
        "output": {
            "category": "Sides",
            "item": "Large Roast-Beef Sandwich",
            "modifiers": [
                "LG"
            ],
            "quantity": 1
        }
}

关于json - "unknown key [_index] for create index",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58447460/

相关文章:

java - 在java中的新窗口中下载PDF

c# - 服务器未返回状态代码为 400 的 JSON (.net)

postman - Newman:未知编码:latin1 在 AWS CodeBuild 上运行 Newman cli 时弹出

java - 使用 postman 复制请求代码的 400 错误请求

spring-security - 如何使用Postman身份验证助手调用JHipster( Spring )OAuth2 Rest服务器

javascript - 在 Angular-Resource 的帮助下将值插入 db.json

ios - 如何将整数值解析为 Json iOS?

elasticsearch - 批量更新未发生

php - 在 Elasticsearch php API 中使用多种类型或索引

python elasticsearch格式数据