title: Elasticsearch error - While trying to search contents in the attachment
body: <p>Am using ingest-attachment processor plugin to index my pdf files and am able to index also using java code. Now, i want to search some contents in my pdf files which is available in elasticsearch.</p>
  
  <p>Am using the below query to search contents in files and am getting error while executing this code.    </p>
  
  <pre><code>SearchRequest contentSearchRequest = new SearchRequest(ATTACHMENT); 
  SearchSourceBuilder contentSearchSourceBuilder = new SearchSourceBuilder();
  contentSearchRequest.types(TYPE);
  QueryBuilder attachmentQB = QueryBuilders.matchQuery("attachment.content", "karthikeyan");
  contentSearchSourceBuilder.query(attachmentQB);
  contentSearchSourceBuilder.size(50);
  searchRequest.source(contentSearchSourceBuilder);
  SearchResponse contentSearchResponse = null;
  try {
      contentSearchResponse = restHighLevelClient.search(contentSearchRequest);
  } catch (IOException e) {
      e.getLocalizedMessage();
  }
  
  SearchHit[] contentSearchHits = contentSearchResponse.getHits().getHits();
  long contenttotalHits=contentSearchResponse.getHits().totalHits;
  System.out.println("condition Total Hits ---&gt;"+contenttotalHits);
  
  for (SearchHit contenthit : contentSearchHits) {
  
      Map&lt;String, Object&gt; sourceAsMap = contenthit.getSourceAsMap();
      System.out.println("-----------&gt;"+sourceAsMap.get("resume"));
  }
  </code></pre>
  
  <p>Please find the document that i have indexed </p>
  
  <pre><code>{
    "_index": "attach_local",
    "_type": "doc",
    "_id": "106",
    "_version": 1,
    "found": true,
    "_source": {
      "resume": "1MzUgZg0KMDAwMDAwMDAwMCA2NTUzNSBmDQowMDAwMDAxODg1IDAwMDAwIG4NCjAwMDAwMDIxMzIgMDAwMDAgbg0KMDAwMDA4NTIzNiAwMDAwMCBuDQp0cmFpbGVyDQo8PC9TaXplIDIwL1Jvb3QgMSAwIFIvSW5mbyA5IDAgUi9JRFs8NDlEMTEzNzA1QjE0RDc0NUI4MkQ4NzhDODZFMzEzREU+PDQ5RDExMzcwNUIxNEQ3NDVCODJEODc4Qzg2RTMxM0RFPl0gPj4NCnN0YXJ0eHJlZg0KODU1MTMNCiUlRU9GDQp4cmVmDQowIDANCnRyYWlsZXINCjw8L1NpemUgMjAvUm9vdCAxIDAgUi9JbmZvIDkgMCBSL0lEWzw0OUQxMTM3MDVCMTRENzQ1QjgyRDg3OEM4NkUzMTNERT48NDlEMTEzNzA1QjE0RDc0NUI4MkQ4NzhDODZFMzEzREU+XSAvUHJldiA4NTUxMy9YUmVmU3RtIDg1MjM2Pj4NCnN0YXJ0eHJlZg0KODYwNjkNCiUlRU9G",
      "attachment": {
        "date": "2018-06-21T10:50:01Z",
        "content_type": "application/pdf",
        "author": "Karthikeyan A S",
        "language": "sv",
        "content": "My first Elastic Search attachment using ingest-attachment plugin. Karthikeyan",
        "content_length": 71
      },
      "postDate": "2018-06-21T10:53:53.161Z",
      "Name": "Karthikeyan"
    }
  }
  </code></pre>
  
  <p>Please find the below error that am getting </p>
  
  <pre><code>ElasticsearchStatusException[Elasticsearch exception [type=search_phase_execution_exception, reason=all shards failed]]
      at org.elasticsearch.rest.BytesRestResponse.errorFromXContent(BytesRestResponse.java:177)
      at org.elasticsearch.client.RestHighLevelClient.parseEntity(RestHighLevelClient.java:573)
      at org.elasticsearch.client.RestHighLevelClient.parseResponseException(RestHighLevelClient.java:549)
      at java.lang.Thread.run(Thread.java:748)
      Suppressed: org.elasticsearch.client.ResponseException: method [GET], host [http://localhost:9200], URI [/attach_local/doc/_search?typed_keys=true&amp;ignore_unavailable=false&amp;expand_wildcards=open&amp;allow_no_indices=true&amp;search_type=query_then_fetch&amp;batched_reduce_size=512], status line [HTTP/1.1 400 Bad Request]
  {"error":{"root_cause":[{"type":"query_shard_exception","reason":"Binary fields do not support searching","index_uuid":"JjE66zAUSKi11FJ_yHVLSA","index":"attach_local"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"attach_local","node":"uPLyU7R5RXeirg8XzRqhnA","reason":{"type":"query_shard_exception","reason":"Binary fields do not support searching","index_uuid":"JjE66zAUSKi11FJ_yHVLSA","index":"attach_local"}}]},"status":400}
          at org.elasticsearch.client.RestClient$1.completed(RestClient.java:357)
  </code></pre>
  
  <p>Please find my mappings details</p>
  
  <pre><code>PUT attach_local
  {
    "mappings" : {
      "doc" : {
        "properties" : {
          "attachment" : {
            "properties" : {
              "content" : {
                "type" : "binary"
              },
              "content_length" : {
                "type" : "long"
              },
              "content_type" : {
                "type" : "text"
              },
              "language" : {
                "type" : "text"
              }
            }
          },
          "resume" : {
            "type" : "text"
          }
        }
      }
    }
  }
  </code></pre>
  
  <p>Am using Elasticsearch version 6.2.3 version </p>