Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Tika in server mode

Tags:

apache-tika

On Tika's website it says (concerning tika-app-1.2.jar) it can be used in server mode. Does anyone know how to send documents and receive parsed text from this server once it is running?

like image 847
Serge Anido Avatar asked Sep 01 '12 21:09

Serge Anido


People also ask

How do I use Tika server?

- GUI mode Use the "--gui" (or "-g") option to start the Apache Tika GUI. You can drag and drop files from a normal file explorer to the GUI window to extract text content and metadata from the files. - Server mode Use the "--server" (or "-s") option to start the Apache Tika server.

What is Apache Tika server?

Apache Tika is a content detection and analysis framework, written in Java, stewarded at the Apache Software Foundation.

What is a tika service?

The Apache Tika™ toolkit detects and extracts metadata and text from over a thousand different file types (such as PPT, XLS, and PDF). All of these file types can be parsed through a single interface, making Tika useful for search engine indexing, content analysis, translation, and much more.


2 Answers

Tika supports two "server" modes. The simpler and original is the --server flag of Tika-App. The more functional, but also more recent is the JAX-RS JSR-311 server component, which is an additional jar.

The Tika-App Network Server is very simple to use. Simply start Tika-App with the --server flag, and a --port ### flag telling it what port to listen on. Then, connect to that port and send it a single file. You'll get back the html version. NetCat works well for this, something like java -jar tika-app.jar --server --port 12345 followed by nc 127.0.0.1 12345 < MyFileToExtract will get you back the html

The JAX-RS JSR-311 server component supports a few different urls, for things like metadata, plain text etc. You start the server with java -jar tika-server.jar, then do HTTP put calls to the appropriate url with your input document and you'll get the resource back. There are loads of details and examples (including using curl for testing) on the wiki page

The Tika App Network Server is fairly simple, only supports one mode (extract to HTML), and is generally used for testing / demos / prototyping / etc. The Tika JAXRS Server is a fully RESTful service which talks HTTP, and exposes a wide range of Tika's modes. It's the generally recommended way these days to interface with Tika over the network, and/or from non-Java stacks.

like image 70
Gagravarr Avatar answered Sep 29 '22 16:09

Gagravarr


Just adding to @Gagravarr's great answer.

When talking about Tika in server mode, it is important to differentiate between two versions which can otherwise cause confusion:

  • tika-app.jar has the --server --port 9998 options to start a simple server
  • tika-server.jar is a separate component using JAX-RS

The first option only provides text extraction and returns the content as HTML. Most likely, what you really want is the second option, which is a RESTful service exposing many more of Tika's features.

You can simply download the tika-server.jar from the Tika project site. Start the server using

java -jar tika-server-x.x.jar -h 0.0.0.0 

The -h 0.0.0.0 (host) option makes the server listen for any incoming requests, otherwise without it it would only listen for requests from localhost. You can also add the -p option to change the port, otherwise it defaults to 9998.

Then, once the server has started you can simply access it using your browser. It will list all available endpoints.

Finally to extract meta data from a file you can use cURL like this:

curl -T testWORD.doc http://example.com:9998/meta 

Returns the meta data as key/value pairs one per line. You can also have Tika return the results as JSON by adding the proper accept header:

curl -H "Accept: application/json" -T testWORD.doc http://example.com:9998/meta 

[Update 2015-01-19] Previously the comment said that tika-server.jar is not available as download. Fixed that since it actually does exist as a binary download.

like image 31
Ingo Renner Avatar answered Sep 29 '22 15:09

Ingo Renner