Caffeinated
Caffeinated

Reputation: 12484

How to use Apache Tika to extract the "Subject” field by using Apache Metadata class ?

I'm trying to extract the "Subject" field from an email, but am having some trouble . I was able to get the "To" and "From" fields already, like so :

String messageTo =  tikaMetadata.MESSAGE_TO;   //Works fine
String toField =  tikaMetadata.get(messageTo); //Works fine


System.out.println("From field is : " + fromField); //Works fine
System.out.println("To field is : "  + toField);    //Works fine


String messageSubj =  tikaMetadata.getValues("Message:Raw-Header:Subject"); 
String subjField =  tikaMetadata.get(messageTo); //Doesn't Work

How would we extract the subject field by using Tika ? any tips helpful thanks

Upvotes: 0

Views: 233

Answers (1)

Nicomedes E.
Nicomedes E.

Reputation: 1334

You can try two ways:

  1. String subjectObs = tikaMetadata.get(tikaMetadata.SUBJECT); but where.SUBJECT is deprecated

  2. String subject = tikaMetadata.get(TikaCoreProperties.DESCRIPTION);probably the substitute that is closest to Metadata.SUBJECT (for more details about TikaCoreProperties look at this: tika documentation)

Upvotes: 6

Related Questions