title: MongoDB-MongoRiver-ElasticSearch-NEST
body: <p>I have setup MongoDB database with Enron mail collection. MongoRiver is used to bridge between Mongo &amp; ElasticSearch. I can access the Mongo Data via REST on ElasticSearch.</p>
  
  <p>While configuring MongoRiver, I have already created an index "MongoIndex"</p>
  
  <p><strong>Issue:</strong> When I use NEST(.NET C#) to connect/fetch the data from ES, it returns 0 document whereas the same query returns result on REST.</p>
  
  <p><strong>MongoDB Details -</strong>
  DB: Enron
  Collection: Messages</p>
  
  <p><strong>ES Details-</strong>
  Index: MongoIndex
  Type: Messages</p>
  
  <h2><strong>Single document format for a message in the collection -</strong></h2>
  
  <pre><code>{
      "_id" : ObjectId("4f2ad4c4d1e2d3f15a000000"),
      "body" : "Here is our forecast\n\n ",
      "subFolder" : "allen-p/_sent_mail",
      "mailbox" : "maildir",
      "filename" : "1.",
      "headers" : {
          "X-cc" : "",
          "From" : "phillip.allen@enron.com",
          "Subject" : "",
          "X-Folder" : "\\Phillip_Allen_Jan2002_1\\Allen, Phillip K.\\'Sent Mail",
          "Content-Transfer-Encoding" : "7bit",
          "X-bcc" : "",
          "To" : "tim.belden@enron.com",
          "X-Origin" : "Allen-P",
          "X-FileName" : "pallen (Non-Privileged).pst",
          "X-From" : "Phillip K Allen",
          "Date" : "Mon, 14 May 2001 16:39:00 -0700 (PDT)",
          "X-To" : "Tim Belden ",
          "Message-ID" : "&lt;18782981.1075855378110.JavaMail.evans@thyme&gt;",
          "Content-Type" : "text/plain; charset=us-ascii",
          "Mime-Version" : "1.0"
      }
  }
  </code></pre>
  
  <hr>
  
  <p>This is my .Net code for NEST to connect Elasticsearch -</p>
  
  <pre><code>    public class Message
      {
          public string id { get; set; }
          public string body { get; set; }
          public string mailbox { get; set; }
          public string filename { get; set; }
  
          [ElasticProperty(Type = FieldType.Nested)]
          public IList&lt;HeadersComponent&gt; headers { get; set; }
      }
  
      public class HeadersComponent
      {
          public string Cc { get; set; }
          public string Bcc { get; set; }
          public string From { get; set; }
          public string Subject { get; set; }
          public string To { get; set; }
          public string Date { get; set; }        
      }
  
  
      Uri node = new Uri("http://localhost:9200");
      ConnectionSettings settings = new ConnectionSettings(node, "MongoIndex");
      ElasticClient client = new ElasticClient(settings);
  
      ISearchResponse&lt;Message&gt; searchResponse = client.Search&lt;Message&gt;(s =&gt; s.Query(q =&gt; q.Term(p =&gt; p.body, "SearchMe"));
  </code></pre>
  
  <p>When I run the above code to search for "SearchMe" text in the email 'body', it returns 0 results.</p>
  
  <p>Need help on this. Its driving me nuts :)</p>