我正在一个包含django,elasticsearch和django-elasticsearch-dsl的项目中。我正在收集大量数据,并通过django-elasticsearch-dsl将其保存到postgres并将其索引到elasticsearch。
我碰到了我不很了解的问题,也没有任何进一步的提示会发生什么:
Django的models.py文件的相关部分:
class LinkDenorm(BaseModel):
...
link = CharField(null=True, max_length=2710, db_index=True)
link_expanded = TextField(null=True, db_index=True)
title = TextField(null=True, db_index=True)
text = TextField(null=True)
...
django-elasticsearch-dsldocuments.py文件的相关部分:@registry.register_document
class LinkDenorm(Document):
link_expanded = fields.KeywordField(attr='link_expanded')
class Index:
name = 'denorms_v10'
class Django:
model = models.LinkDenorm
fields = [
...
'link',
'title',
'text',
...
]
成功建立数据索引之后,我验证索引是否包含正确的字段:curl -X GET -u <myuser>:<mypasswd> "http://<my-hostname>/denorms_v10/?pretty"
{
"denorms_v10" : {
"mappings" : {
"properties" : {
...
"link" : {
"type" : "text"
},
"title" : {
"type" : "text"
},
"text" : {
"type" : "text"
}
"link_expanded" : {
"type" : "keyword"
},
...
}
}
}
}
经过一定时间(有时数周,有时数天)后,索引字段将更改。执行与以前相同的CURL查找会给我:curl -X GET -u <myuser>:<mypasswd> "http://<my-hostname>/denorms_v10/?pretty"
{
"denorms_v10" : {
"mappings" : {
"properties" : {
...
"link" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"title" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"text" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"link_expanded" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
...
}
}
}
}
发生更改后,查询失败,因为数据类型不正确。在调查了elasticsearch和django日志之后,没有任何东西可以提供有关该索引发生了什么的线索。我有点迷失了方向。任何建议都是最欢迎的。谢谢!
最佳答案
Miha,您的索引可能使用一种没有任何索引模板的ILM。
您查询别名,并且别名正在更改。
您一方的某个过程会定期删除索引(取决于索引的大小或其中的文档数)
然后,当您的应用再次发布时,它将使用默认的Elastic映射重新创建索引。
关于django - Elasticsearch文档字段类型索引自动更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63489302/