gpt4 book ai didi

node.js - elasticsearch中的可编辑文档字段

转载 作者:行者123 更新时间:2023-12-03 01:57:42 24 4
gpt4 key购买 nike

我的文档包含一个对象,该对象的属性在运行时可编辑(添加/删除/编辑)。

{
"testIndex" : {
"mappings" : {
"documentTest" : {
"properties" : {
"typeTestId" : {
"type" : "string",
"index" : "not_analyzed"
},
"createdDate" : {
"type" : "date",
"format" : "dateOptionalTime"
},
"designation" : {
"type" : "string",
"fields" : {
"raw" : {
"type" : "string",
"index" : "not_analyzed"
}
}
},
"id" : {
"type" : "string",
"index" : "not_analyzed"
},
"modifiedDate" : {
"type" : "date",
"format" : "dateOptionalTime"
},
"stuff" : {
"type" : "string"
},
"suggest" : {
"type" : "completion",
"analyzer" : "simple",
"payloads" : true,
"preserve_separators" : true,
"preserve_position_increments" : true,
"max_input_length" : 50,
"context" : {
"typeTestId" : {
"type" : "category",
"path" : "typeTestId",
"default" : [ ]
}
}
},
"values" : {
"properties" : {
"Att1" : {
"type" : "string"
},
"att2" : {
"type" : "string"
},
"att400" : {
"type" : "date",
"format" : "dateOptionalTime"
}
}
}
}
}
}
}
}

字段值是可以通过typeTest进行编辑的对象,因此,如果我在typeTestit中进行了更改,则应在此处反射(reflect)出来。如果我创建一个新字段没有问题,但是应该可以编辑或删除typeTest中的现有字段。例如,如果我删除values.att1,则所有documentTest都将丢失这些值,并且应更新映射。

就我所见,如果不重新编制索引,我们将无法做到这些。所以现在,我的解决方案是删除 Elasticsearch 中的字段,就像提到的 in this question一样,并让工作人员在需要时不时重新索引。

在我看来这不是一个“解决方案”。在Elasticsearch中是否有更好的方法来拥有此类文档?具有这种灵活性而不必时不时重新编制索引?

最佳答案

您可以使用Update API删除,添加或修改字段。
问题是文档在Elasticsearch中是不可变的,因此当您使用更新API进行某些更改时,它以mark as deleted to old one and add a new one with the updates的方式执行。
删除和创建新文档对您是透明的,因此您无需重新索引或执行任何其他操作。不利的一面是,如果您打算修改大量文档(例如用于更新5百万个文档的更新查询),则节点的I / O密集度很高。
顺便说一句,这也适用于删除

关于node.js - elasticsearch中的可编辑文档字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35435532/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com