Re-index object with new fields

时间:2015-06-15 14:17:11

标签: elasticsearch nest

It seems like as long as the id field is maintained, its super easy to re-index a document by simply calling Index(), but is there a way to given an object was updated and new fields were added, to have it include these new fields in the index?

I'm not explicitly creating any indexing, but rather just telling it to index these objects in this index itself. I've been able to delete the document and reindex and it does exactly what I'd expect. (I know theres no magic just update all these documents with a this new field, but if I knew "schema" changed, I could have a manual process handle this).

1 个答案:

答案 0 :(得分:0)

如果你想更新,你可以这样做:

        var response = _Instance.Update<BusinessElastic, object>(u => u
             .Index(elasticSearchIndex)
             .Type("business")
             .Id(result.Hits.FirstOrDefault().Id)
             .Doc(new Document {Column1="", Column2=""})
             .DocAsUpsert()
         );