Exception in Attachment-plugin


(IronMike) #1

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.
To view this discussion on the web visit 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.


(system) #2