# How to index custom json with C# object using NEST

**URL:** <https://discuss.elastic.co/t/how-to-index-custom-json-with-c-object-using-nest/275431>\
**Category:** Elasticsearch\
**Created:** [June 9, 2021, 11:56am UTC](https://discuss.elastic.co/t/how-to-index-custom-json-with-c-object-using-nest/275431 "2021-06-09T11:56:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lilan\_Silva](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lilan_silva/32/90052_2.png) [@Lilan\_Silva](https://discuss.elastic.co/u/Lilan_Silva)\
**Post date:** [June 9, 2021, 11:56am UTC](https://discuss.elastic.co/t/how-to-index-custom-json-with-c-object-using-nest/275431/1 "2021-06-09T11:56:55Z")

</div>

I am new to elastic search and we need to migrate from mongodb to elastic. we used

```auto
public class Book
    {
        [BsonId]
        public string Id { get; set; }

        public string ApplicationId { get; set; }

        public string UserName { get; set; }

        public string UserId{ get; set; }

        public DateTime CurrDate { get; set; }

        public int Counter { get; set; }

        public DateTimeOffset CurrDateOffset { get; set; }

        [BsonExtraElements]
        public BsonDocument Metadata { get; set; }
    }

```

BsonDocument support custom json object. so I can insert an object with pre-define property & custom json string

As a example

```auto
var basonDoc = BsonSerializer.Deserialize<BsonDocument>(@"{
   ""emp-name"":""Kasun kalhara"",
   ""emp-age"":30,
   ""emp-position"":""Associate Developer""
}");

```

```auto
var indexResponse = await elasticClient.IndexDocument(new BookElasticSearch
            {
                Id = Guid.NewGuid().ToString(),
                UserId = "test@test.ai",
                UserName = "test test Silva",
                CurrDate = DateTime.Now,
                CurrDateOffset = DateTimeOffset.Now,
                Counter = -1,
                Metadata = basonDoc
            });

```

How can I do that using NEST or any way in .net core

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 7, 2021, 11:56am UTC](https://discuss.elastic.co/t/how-to-index-custom-json-with-c-object-using-nest/275431/2 "2021-07-07T11:56:58Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
