# Exception in Attachment-plugin

**URL:** <https://discuss.elastic.co/t/exception-in-attachment-plugin/15350>\
**Category:** Elasticsearch\
**Created:** [January 21, 2014, 11:43pm UTC](https://discuss.elastic.co/t/exception-in-attachment-plugin/15350 "2014-01-21T23:43:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![IronMike](https://avatars.discourse-cdn.com/v4/letter/i/e9a140/32.png) [@IronMike](https://discuss.elastic.co/u/IronMike)\
**Post date:** [January 21, 2014, 11:43pm UTC](https://discuss.elastic.co/t/exception-in-attachment-plugin/15350/1 "2014-01-21T23:43:34Z")

</div>

I tried to follow a simple example on indexing a pdf document, I am using  
java API. Any clue why I get this exception? By the way the plugin is  
installed,

I verified by starting ES instance

[plugins] loaded [mapper-attachments, cloud-aws], sites  
[bigdesk, hello-elasticsearch, head]

//Exception when running java

Exception in thread "main"  
org.elasticsearch.index.mapper.MapperParsingException: mapping [attachment]

at org.elasticsearch.cluster.metadata.MetaDataCreateIndexService$2.execute(  
MetaDataCreateIndexService.java:314)

at org.elasticsearch.cluster.service.InternalClusterService$UpdateTask.run(  
InternalClusterService.java:300)

at  
org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.run(  
PrioritizedEsThreadPoolExecutor.java:135)

at java.util.concurrent.ThreadPoolExecutor.runWorker(  
ThreadPoolExecutor.java:1110)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(  
ThreadPoolExecutor.java:603)

at java.lang.Thread.run(Thread.java:722)

Caused by: org.elasticsearch.index.mapper.MapperParsingException: No  
handler for type [attachment] declared on field [file]

at  
org.elasticsearch.index.mapper.object.ObjectMapper$TypeParser.parseProperties(  
ObjectMapper.java:260)

at org.elasticsearch.index.mapper.object.ObjectMapper$TypeParser.parse(  
ObjectMapper.java:218)

at org.elasticsearch.index.mapper.DocumentMapperParser.parse(  
DocumentMapperParser.java:201)

at org.elasticsearch.index.mapper.DocumentMapperParser.parseCompressed(  
DocumentMapperParser.java:183)

at org.elasticsearch.index.mapper.MapperService.parse(MapperService.java:322  
)

at org.elasticsearch.index.mapper.MapperService.merge(MapperService.java:200  
)

at org.elasticsearch.cluster.metadata.MetaDataCreateIndexService$2.execute(  
MetaDataCreateIndexService.java:311)

... 5 more

Here is my code:

public class PDFDemo1 {

```
   private static Node node;

      static Client client;

    public static void main(String[] args) throws Exception {

             node = nodeBuilder().local(true).node();

              client = node.client();

              mapperAttachmentTest();

   }

     public static void mapperAttachmentTest() throws Exception {

                String idxName = "test";

                String idxType = "attachment";

                XContentBuilder map = jsonBuilder().startObject()

                       .startObject(idxType)

                         .startObject("properties")

                           .startObject("file")

                             .field("type", "attachment")

                             .startObject("fields")

                               .startObject("title")

                                 .field("store", "yes")

                               .endObject()

                               .startObject("file")

                                 .field("term_vector",

```

"with\_positions\_offsets")

```
                                 .field("store","yes")

                               .endObject()

                             .endObject()

                           .endObject()

                         .endObject()

                    .endObject();

               try {

                  client.admin().indices().prepareDelete(idxName).

```

execute().actionGet();

```
               } catch (Exception ex) {}

               CreateIndexResponse resp = client.admin().indices().

```

prepareCreate(idxName).setSettings(

```
                       ImmutableSettings.settingsBuilder()

                       .put("number_of_shards", 1)

                       .put("index.numberOfReplicas", 1))

                       .addMapping("attachment", map).execute().

```

actionGet();

```
               String pdfPath = ClassLoader.getSystemResource(

```

"fn6742.pdf").getPath();

```
               String data64 = org.elasticsearch.common.Base64.

```

encodeFromFile(pdfPath);

```
               XContentBuilder source = jsonBuilder().startObject()

                       .field("file", data64).endObject();

               IndexResponse idxResp = client.prepareIndex().setIndex(

```

idxName).setType(idxType).setId("80")

```
                       .setSource(source).setRefresh(true).execute().

```

actionGet();

```
               String queryString = "amplifier";

               QueryBuilder query = QueryBuilders.queryString(

```

queryString);

```
               SearchRequestBuilder searchBuilder = client.prepareSearch

```

().setQuery(query)  
.addField("title")

```
                      .addHighlightedField("file");

               SearchResponse search = searchBuilder.execute().actionGet

```

();

```
              long numofHits = search.getHits().totalHits();

              System.out.print(numofHits);

            // assertThat(search.getHits().hits().length, equals(1));

             // 

```

assertThat(search.getHits().getAt(0).highlightFields().get("file"),  
notNullValue());

```
             // 

```

assertThat(search.hits().getAt(0).highlightFields().get("file").toString(),  
containsString("_Amplifier_"));

```
               client.close();

              }

```

}

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/1c438d30-cb84-445e-9790-66586ca14758%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1c438d30-cb84-445e-9790-66586ca14758%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [July 6, 2017, 1:55am UTC](https://discuss.elastic.co/t/exception-in-attachment-plugin/15350/2 "2017-07-06T01:55:30Z")

</div>


