How do I update an existing document inside ElasticSearch index using NEST?

前端 未结 5 797
一生所求
一生所求 2020-12-24 06:56

I am trying to update an existing indexed document. I have indexed tags, title and owners field. Now when the user changes the title, I need to find and update the document

5条回答
  •  盖世英雄少女心
    2020-12-24 07:46

    I have successfully updated existing items in my Elasticsearch index with NEST using a method like the following. Note in this example, you only need to send a partial document with the fields that you wish to be updated.

        // Create partial document with a dynamic
        dynamic updateDoc = new System.Dynamic.ExpandoObject();
        updateDoc.Title = "My new title";
    
        var response = client.Update(u => u
            .Index("movies")
            .Id(doc.Id)
            .Document(updateDoc)
         );
    

    You can find more examples of ways to send updates in the NEST Update Unit Tests from the GitHub Source.

提交回复
热议问题