首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >“create index的未知键[_index]”

“create index的未知键[_index]”
EN

Stack Overflow用户
提问于 2019-10-18 17:04:15
回答 2查看 5.4K关注 0票数 0
代码语言:javascript
复制
Elasticsearch version : 7.1
Postman version : 7.8.0

我的url如下所示

代码语言:javascript
复制
http://localhost:9200/menu

我遇到的错误:

代码语言:javascript
复制
{
    "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索引中。

我已经被这个问题困扰了好几个小时了。我试过不同的方法,但都不管用。我想做的是使用postman插入到elastic search中。我已经定义了我的mappings,如下所示。

代码语言:javascript
复制
  "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"
                        }
                    }
                }
            }
        }

我将下面的身体传递给邮递员。

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

Update 1:在将body修改为下面的内容之后。

代码语言:javascript
复制
{
    "index": {
        "_index": "catalog",
        "_type": "_doc"
    },
    "key":{
        "input": "roast beef",
        "output": {
            "category": "Sides",
            "item": "Large Roast-Beef Sandwich",
            "modifiers": [
                "LG"
            ],
            "quantity": 1
        }
    }
}

我现在得到了错误

代码语言:javascript
复制
{
    "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
}

将body更改为以下内容后的Update 2:

代码语言:javascript
复制
{       
        "_index": "catalog",
        "_type": "_doc",     
        "input": "roast beef",
        "output": {
            "category": "Sides",
            "item": "Large Roast-Beef Sandwich",
            "modifiers": [
                "LG"
            ],
            "quantity": 1
        }
}

我得到以下错误

代码语言:javascript
复制
{
    "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
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-10-18 17:26:24

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

代码语言:javascript
复制
{       
        "_index": "catalog",
        "_type": "_doc"     
        "input": "roast beef",
        "output": {
            "category": "Sides",
            "item": "Large Roast-Beef Sandwich",
            "modifiers": [
                "LG"
            ],
            "quantity": 1
        }
}
票数 1
EN

Stack Overflow用户

发布于 2019-10-18 20:14:49

http://localhost:9200/menu/发出一个PUT调用(假设您在默认端口上的本地运行elastic,索引名称为'menu')。

在正文中包括你的maaping,如下所示:

代码语言:javascript
复制
 {
    "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"
                    }
                }
            }
        }
    }
}

这将创建索引,结果如下(响应):

代码语言:javascript
复制
 {
    "acknowledged": true,
    "shards_acknowledged": true,
    "index": "menu"
 }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58447460

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档