首页 > 解决方案 > “用于创建索引的未知键 [_index]”

问题描述

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 searchusing 中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"
                        }
                    }
                }
            }
        }

我将以下身体传递给邮递员。

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

Update 1: 把身体改成下面这个。

{
    "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:把身体改成这个后

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

标签: jsonelasticsearchpostman

解决方案


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

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

推荐阅读