Extract exctly/only json docs from ES Index into C# (NEST)

Hello elastic.co,

New user here, hence am learning the forum rules as well.  Forum Admins, if this was asked previously, pardon me. I am an intermediate .Net C# programmer and novice ElasticSearch user.

Here is my issue:

From a .Net (C#) Console app, I need to (1) connect to an ES instance, (2) query a specific index, (3) pull ALL the docs from the index (which number about 10k - 12k per day, so there will be paging/scan/scroll used here) and (4) loop through each json doc and (5) search for a keyword in one or more of the key value pairs.

So, I simply need to pull down the source json data into a string and search through it. I need to keep doing this until I've cycled through all the docs in the index. I can successfully accomplish 1 - 3. **But I cannot get at the json data in step 4**. HOW DO I SIMPLY GET AT THE JSON DATA in the response object below?

            var response = esClient.Search<Object>(s => s
                                             .From(0)                                   //starting from this initial doc
                                             .Size(1000)                               //how many docs to bring back
                                             .Index("sample_idx")
                                             .Query(q => q.MatchAll())
                                             .Scroll("60s")                          //scroll time(out)
                                             );


 I've tried response.Body (doesn't seem to exist in intellisense), response.Document.Any (also doesn't exist). response.hit in Hits ony seems to give me each key value in each json.


  Any help (sample code) would greatly be appreciated. Thanks all!

prgmrESNet

Welcome to our community! :smiley:
Can you please edit your topic and remove the non-code formatting, it's really hard to read as it is now.

@ warkolm, I've re-pasted the posting here again, with code enclosed in back ticks. Hope it helps.

Here is my issue:

From a .Net (C#) Console app, I need to (1) connect to an ES instance, (2) query a specific index, (3) pull ALL the docs from the index (which number about 10k - 12k per day, so there will be paging/scan/scroll used here) and (4) loop through each json doc and (5) search for a keyword in one or more of the key value pairs.

So, I simply need to pull down the source json data into a string and search through it. I need to keep doing this until I've cycled through all the docs in the index. I can successfully accomplish 1 - 3. **But I cannot get at the json data in step 4**. HOW DO I SIMPLY GET AT THE JSON DATA in the response object below?
                var response = esClient.Search<Object>(s => s
                                                 .From(0)                                   //starting from this initial doc
                                                 .Size(1000)                               //how many docs to bring back
                                                 .Index("sample_idx")
                                                 .Query(q => q.MatchAll())
                                                 .Scroll("60s")                          //scroll time(out)
                                                 );
 I've tried response.Body (doesn't seem to exist in intelli-sense), response.Document.Any (also doesn't exist). response.hit in Hits only seems to give me each key value in each json.


  Any help (sample code) would greatly be appreciated. Thanks all!

prgmrESNet

Hello. Is anyone able to assist with this?

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