# Nest \_mget convert \_source to dynamic type

**URL:** <https://discuss.elastic.co/t/nest-mget-convert-source-to-dynamic-type/146552>\
**Category:** Elasticsearch\
**Created:** [August 29, 2018, 3:22pm UTC](https://discuss.elastic.co/t/nest-mget-convert-source-to-dynamic-type/146552 "2018-08-29T15:22:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Doug\_Nelson1](https://avatars.discourse-cdn.com/v4/letter/d/958977/32.png) [@Doug\_Nelson1](https://discuss.elastic.co/u/Doug_Nelson1)\
**Post date:** [August 29, 2018, 3:22pm UTC](https://discuss.elastic.co/t/nest-mget-convert-source-to-dynamic-type/146552/1 "2018-08-29T15:22:38Z")

</div>

When working with Nest client and doing a search, the Docs collection can be rendered as a dynamic object

`var response = es.Search<dynamic>(s => s.MatchAll());`

When doing an mget, the response returns a collection of hits which will have the Source property. What is the best way to convert the source to be the same as what we have in the Documents collection from a search result.

Below is the code snippet I am using.

```auto
            //create list of multiget operations
            var ids = new List<MultiGetOperation<dynamic>>();
            foreach (var id in uniqueKeys.Keys)
            {
                ids.Add(new MultiGetOperation<dynamic>(id)
                {
                    Type = "doc",
                    Index = uniqueKeys[id].Index //documents can live in different indices
                });
            }

            //return the hits from elastic
            var results = es.MultiGet(
                
                new MultiGetRequest
                {
                    Documents = ids,
                    
                });

            foreach( var hit in results.Hits)
            {
                 // not sure what to do here as this does not work
                dynamic h = hit.Source;
                uniqueKeys[h.item_id].Info = h;
            }

```

---

<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:** [September 26, 2018, 3:22pm UTC](https://discuss.elastic.co/t/nest-mget-convert-source-to-dynamic-type/146552/2 "2018-09-26T15:22:46Z")

</div>

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