我正在尝试使用python中的elasticsearch库将对象保存在elastic内部。以下是我正在使用的班级
mongoose.connect(
"mongodb://username:password@ds243212.mlab.com:43212/userinfo",
{useNewUrlParser : true},
{useMongoClient: true},
function(err , db){
if(err) console.log(err);
console.log("connection success");
}
下面是我的弹性贴图
from elasticsearch_dsl import DocType, Date, InnerDoc, Text, Object
class Child(Object):
child1 = Text()
child2 = Text()
class Parent(DocType):
parent1 = Object()
parent2 = Date()
parent3 = Date()
parent4 = Text()
parent5 = Child()
class Meta:
index = 'my_index'
如果我将类型更改为“对象”并以python代码检索文档,则会出现以下错误。
{
"mappings": {
"doc": {
"properties": {
"parent5": {
"type": "object",
"child1": {
"tracking_number": {
"type": "text"
},
"child2": {
"type": "text"
},
}
},
"parent1": {
"type": "object"
},
"parent2": {
"type": "text"
},
"parent3": {
"type": "date"
},
"parent4": {
"type": "date"
}
}
}
}
}
如果我将类型更改为'InnerDoc',则可以检索文档,但无法将其保存为弹性文件。
我假设我的映射是错误的,但不确定。 任何帮助/见解将不胜感激。 预先感谢
答案 0 :(得分:0)
您需要指定:
class Child(InnerDoc):
...
class Parent(Document):
child = Object(Child)
您还可以在https://github.com/elastic/elasticsearch-dsl-py/blob/master/examples/parent_child.py
中看到一个复杂的示例希望这会有所帮助!