我试图在Elasticsearch上映射json结构,但似乎有些错误,因为当我从Windows提示符启动curl命令时,除了下划线脉冲之外没有任何附加内容。
我使用这个curl命令:
curl -H "Content-Type: application/json" -XPUT http://localhost:9200/technogym -d "{\"mappings\":{\"id\":{\"type\":\"string\"},\"key\":{\"type\":\"string\"},\"value\":{\"type\":\"object\",\"properties\":{\"rev\":{\"type\":\"string\"}}},\"doc\":{\"type\":\"object\",\"properties\":{\"_id\":{\"type\":\"string\"},\"_rev\":{\"type\":\"string\"},\"userID\":{\"type\":\"string\"},\"conversation_id\":{\"type\":\"string\"},\"input\":{\"type\":\"object\",\"properties\":{\"text\":{\"type\":\"string\"}}},\"output\":{\"type\":\"object\",\"properties\":{\"text\":{\"type\":\"string\"}}},\"node_visited\":{\"type\":\"string\"},\"intents\":{\"properties\":{\"intent\":{\"type\":\"string\"},\"confidence\":{\"type\":\"string\"}}},\"entities\":{\"type\":\"object\",\"properties\":{\"entity\":{\"type\":\"string\"},\"location\":{\"type\":\"string\"},\"value\":{\"type\":\"string\"},\"confidence\":{\"type\":\"string\"}}},\"timestamp\":{\"type\":\"date\"}}}}}"
这里我的jsonwith映射(只是为了让它更具可读性):
修改
{"mappings": {
"_default_": {
"properties": {
"id": {
"type": "string"
},
"key": {
"type": "string"
},
"value": {
"type": "object",
"properties": {
"rev": {
"type": "string"
}
}
},
"doc": {
"type": "object",
"properties": {
"_id": {
"type": "string"
},
"_rev": {
"type": "string"
},
"userID": {
"type": "string"
},
"conversation_id": {
"type": "string"
},
"input": {
"type": "object",
"properties": {
"text": {
"type": "string"
}
}
},
"output": {
"type": "object",
"properties": {
"text": {
"type": "string"
}
}
},
"node_visited": {
"type": "string"
},
"intents": {
"properties": {
"intent": {
"type": "string"
},
"confidence": {
"type": "string"
}
}
},
"entities": {
"type": "object",
"properties": {
"entity": {
"type": "string"
},
"location": {
"type": "string"
},
"value": {
"type": "string"
},
"confidence": {
"type": "string"
}
}
},
"timestamp": {
"type": "date"
}
}
}
}
}}}
我不知道为什么我无法上传此映射。
感谢您的帮助。
答案 0 :(得分:1)
您需要将mapping
更改为mappings
。
{
"mappings": { ==> change this
"_default_": {
"properties": {
"id": {
"type": "string"
},
"key": {
"type": "string"
},
"value": {
"type": "object",
"properties": {
"rev": {
"type": "string"
}
}
},
"doc": {
"type": "object",
"properties": {
"_id": {
"type": "string"
},
"_rev": {
"type": "string"
},
"userID": {
"type": "string"
},
"conversation_id": {
"type": "string"
},
"input": {
"type": "object",
"properties": {
"text": {
"type": "string"
}
}
},
"output": {
"type": "object",
"properties": {
"text": {
"type": "string"
}
}
},
"node_visited": {
"type": "string"
},
"intents": {
"properties": {
"intent": {
"type": "string"
},
"confidence": {
"type": "string"
}
}
},
"entities": {
"type": "object",
"properties": {
"entity": {
"type": "string"
},
"location": {
"type": "string"
},
"value": {
"type": "string"
},
"confidence": {
"type": "string"
}
}
},
"timestamp": {
"type": "date"
}
}}}}}}
答案 1 :(得分:1)
创建索引
curl -XPUT localhost:9200/technogym
{"acknowledged":true}
然后将您的映射应用于您想要的任何类型,例如。 technogym_type
curl -X PUT localhost:9200/technogym/technogym_type/_mapping -d '{
"properties": {
"id": {
"type": "string"
},
"key": {
"type": "string"
},
"value": {
"type": "object",
"properties": {
"rev": {
"type": "string"
}
}
},
"doc": {
"type": "object",
"properties": {
"_id": {
"type": "string"
},
"_rev": {
"type": "string"
},
"userID": {
"type": "string"
},
"conversation_id": {
"type": "string"
},
"input": {
"type": "object",
"properties": {
"text": {
"type": "string"
}
}
},
"output": {
"type": "object",
"properties": {
"text": {
"type": "string"
}
}
},
"node_visited": {
"type": "string"
},
"intents": {
"properties": {
"intent": {
"type": "string"
},
"confidence": {
"type": "string"
}
}
},
"entities": {
"type": "object",
"properties": {
"entity": {
"type": "string"
},
"location": {
"type": "string"
},
"value": {
"type": "string"
},
"confidence": {
"type": "string"
}
}
},
"timestamp": {
"type": "date"
}
}
}
}
}'
{"acknowledged":true}
但是,如果您动态地想要创建索引和映射,只需将JSON文档修复到需要mappings
(复数)的位置,然后输入所需类型的名称。 (类型等同于RDBMS表名称)
curl -X PUT localhost:9200/technogym1 -d '
{
"mappings": {
"technogym_type1": {
"properties": {
"id": {
"type": "string"
},
"key": {
"type": "string"
},
"value": {
"type": "object",
"properties": {
"rev": {
"type": "string"
}
}
},
"doc": {
"type": "object",
"properties": {
"_id": {
"type": "string"
},
"_rev": {
"type": "string"
},
"userID": {
"type": "string"
},
"conversation_id": {
"type": "string"
},
"input": {
"type": "object",
"properties": {
"text": {
"type": "string"
}
}
},
"output": {
"type": "object",
"properties": {
"text": {
"type": "string"
}
}
},
"node_visited": {
"type": "string"
},
"intents": {
"properties": {
"intent": {
"type": "string"
},
"confidence": {
"type": "string"
}
}
},
"entities": {
"type": "object",
"properties": {
"entity": {
"type": "string"
},
"location": {
"type": "string"
},
"value": {
"type": "string"
},
"confidence": {
"type": "string"
}
}
},
"timestamp": {
"type": "date"
}
}
}
}
}
}
}'
{"acknowledged":true,"shards_acknowledged":true}