json - “用于创建索引的未知键 [_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 search
using 中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
}
解决方案
您发送的 json 正文格式不正确。括号没有按正确的顺序关闭,并且 body 缺少键名。下面是正确的json格式
{
"_index": "catalog",
"_type": "_doc"
"input": "roast beef",
"output": {
"category": "Sides",
"item": "Large Roast-Beef Sandwich",
"modifiers": [
"LG"
],
"quantity": 1
}
}
推荐阅读
- angular - 如何将数组值传递给html?
- php - 用于将旧 Drupal 项目设置(.yml 文件)导出到新项目的自定义 Drush 命令
- java - 转义表达式:反斜杠
- ubuntu - eBPF / XDP 无法在 Ubuntu 16.04.6 上编译
- html - 从花括号调用定义在脚本标签内的函数
- postgresql - NpgsqlException:错误:22P02:json 类型的输入语法无效
- abap - 拒绝原因的用户退出 VA01
- ruby-on-rails - Rails对数组属性的多项选择不起作用
- java - 如何更改禁用的 jbutton 的颜色?
- wpf - Prism/WPF 中的新外壳/窗口显示错误视图