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

标签 node.js elasticsearch

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

{
  "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/

相关文章:

javascript - Web 应用程序中的 Node.js cron 作业

javascript - 如何正确使用Parse.query.equalTo?

elasticsearch - 如何计算字段在特定范围内的文档数?

c# - 从索引中排除属性

indexing - 处理现有字段类型的更改?

elasticsearch - 如何使用java在Elasticsearch中删除文档的字段属性?

node.js - Sequelize : Get Subquery/Raw Query as model for include

node.js - 发送电子邮件 sendgrid 在促销选项卡中收到,而不是在主要选项卡中

javascript - 在 NodeJS 中使用变换/双工流

elasticsearch - Elasticsearch -使用动态对象和通配符查询