“用于创建索引的未知密钥[_index]”

时间:2019-10-18 09:04:14

标签: 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"
                        }
                    }
                }
            }
        }

我把下面的这个身体交给邮递员。

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

2 个答案:

答案 0 :(得分:0)

您要发送的json正文格式不正确。括号arent按正确的顺序关闭,并且机身缺少关键名称。下面是正确的json格式

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

答案 1 :(得分:0)

http://localhost:9200/menu/进行PUT调用(假设您在默认端口的本地弹性运行,并且索引名称为“ menu”)。

在身体中包括以下内容:

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

这将创建具有以下结果(响应)的索引:

 {
    "acknowledged": true,
    "shards_acknowledged": true,
    "index": "menu"
 }