title: Indexing pdf files in Elasticsearch 2 with Nest 2
body: <p>I want to index PDF files into Elasticsearch as an attachment and then query over its content. So far I try to index the document but the file is not been attached to it or at least elastichq is not able to show it and the elasticsearch is printing an error. </p>
  
  <p>This is the indexing:</p>
  
  <pre><code>var attachment = new Attachment ();
  string path = "bankvsmartin.pdf";
  attachment.Name = path;
  attachment.Content = Convert.ToBase64String (File.ReadAllBytes(path));
  attachment.ContentType = "application/pdf";
  cases.Add( new Case{
      Author="Martin Luther 2",
      CaseName="Bank vs Martin",
      File= attachment
  });
  var indexName = "indexname";
  client.Map&lt;Case&gt;(m =&gt; m.UpdateAllTypes());
  foreach (var caze in cases)
  {
      var rsp = client.Index (caze, i=&gt;i.Index(indexName).Type("cases"));
  }
  </code></pre>
  
  <p>And the classes and mapping definitions:</p>
  
  <pre><code>[ElasticsearchType(Name = "cases")]
  public class Case
  {
      public string Author { get; set; }
      public string CaseName { get; set; }
      [Attachment(Store = true)]
      public Attachment File { get; set; }
  
      public Case ()
      {
  
      }
  
      public override string ToString()
      {
          return "Case: " + Author + " - " + File.Name;
      }
  }
  
  
  public class Attachment
  {
      [String(Name = "_content")]
      public string Content { get; set; }
  
      [String(Name = "_content_type")]
      public string ContentType { get; set; }
  
      [String(Name = "_name")]
      public string Name { get; set; }
  
  }
  </code></pre>
  
  <p>Elasticsearch error in console when trying to retrieve the attachment:</p>
  
  <pre><code>emoteTransportException[[Sin-Eater][127.0.0.1:9300][indices:data/read
  
  /search[phase/fetch/id]]]; nested: IllegalArgumentException[field [file] isn't a leaf field];
  Caused by: java.lang.IllegalArgumentException: field [file] isn't a leaf field
      at org.elasticsearch.search.fetch.FetchPhase.execute(FetchPhase.java:138)
      at org.elasticsearch.search.SearchService.executeFetchPhase(SearchService.java:590)
      at org.elasticsearch.search.action.SearchServiceTransportAction$FetchByIdTransportHandler.messageReceived(SearchServiceTransportAction.java:408)
      at org.elasticsearch.search.action.SearchServiceTransportAction$FetchByIdTransportHandler.messageReceived(SearchServiceTransportAction.java:405)
      at org.elasticsearch.transport.TransportService$4.doRun(TransportService.java:350)
      at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      at java.lang.Thread.run(Thread.java:745)
  </code></pre>
  
  <p>I am trying to accomplish pretty much the same thing as in <a href="https://stackoverflow.com/questions/14781946/elasticsearch-attachment-type-nest-c">this question</a> but with a more recent version of <a href="https://www.elastic.co/blog/ga-release-of-nest-2-0-our-dot-net-client-for-elasticsearch" rel="nofollow noreferrer">Nest</a>.</p>
  
  <p>Using Elasticsearch 2.2, Nest 2.0.2, Mono / .Net 4.5</p>
  
  <h2>UPDATE</h2>
  
  <p>Here is the generated mapping</p>
  
  <pre><code>"mappings": {
    "cases": {
      "properties": {
        "author": {
          "type": "string"
        },
        "case_name": {
          "type": "string"
        },
        "file": {
          "properties": {
            "_content": {
              "type": "string"
            },
            "_content_type": {
              "type": "string"
            },
            "_name": {
              "type": "string"
            }
          }
        }
      }
    }
  </code></pre>