# Indexing Images

**URL:** https://discuss.elastic.co/t/indexing-images/15929
**Category:** Elasticsearch
**Created:** [February 20, 2014, 4:38pm UTC](https://discuss.elastic.co/t/indexing-images/15929 "2014-02-20T16:38:31Z")
**Posts on this page:** 4
**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: [February 20, 2014, 4:38pm UTC](https://discuss.elastic.co/t/indexing-images/15929/1 "2014-02-20T16:38:31Z")

</div>

I am a bit confused about this topic, I would like to index images  
(png,jpegs, gifs...), my understanding is that I need to extract and index  
text portions from images, I don't really care for the meta data. So, I  
looked online and decided to use apache Tika which I also use to extract  
text and index pdfs (pdfs work fine).

- How do I get the text part of images? All I am able to extract is  
metadata which I don't need.
- Ideally I want to say if this image has no text to extract, then  
discard/ignore? Can you please clarify this topic a bit more and provide  
any samples if available? Additionaly, I don't want to store the 64 based  
encoded document.

PutMappingResponse putMappingResponse = new PutMappingRequestBuilder(

```
                               client.admin().indices() ).setIndices(

```

INDEX\_NAME).setType(INDEX\_TYPE).setSource(  
XContentFactory.jsonBuilder  
().startObject()

```
                                .startObject(INDEX_TYPE)

                                   .startObject("_source").field(

```

"enabled","no").endObject() //I believe this line will not store the base  
64 whole \_source, below I store the text portion of file only "file"

```
                                   .startObject("properties")

                                     .startObject("file")

                                       .field( "term_vector", 

```

"with\_positions\_offsets" )

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

                                       .field( "type", "attachment" )

                                       .field("fields")

                                          .startObject()

                                            .startObject("file")

                                                .field("store", "yes")

                                            .endObject()

                                        .endObject()

                                     .endObject()

                                   .endObject()

                                 .endObject()

                               .endObject()

                           ).execute().actionGet();

    public static void testImage(File file) throws IOException, 

```

SAXException,TikaException {

```
   Tika tika = new Tika();

   InputStream inputStream = new BufferedInputStream( new 

```

FileInputStream(file));

Metadata metadata = new Metadata();

ContentHandler handler = new DefaultHandler();

Parser parser = new JpegParser();

ParseContext context = new ParseContext();

String mimeType = tika.detect(inputStream);

```
metadata.set(Metadata.CONTENT_TYPE, mimeType);

```

parser.parse(inputStream,handler,metadata,context);

for(int i = 0; i \<metadata.names().length; i++) { //metaData -I don't  
care for this

```
   String name = metadata.names()[i];
   System.out.println(name + " : " + metadata.get(name));

 }

```

}

--  
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/dbfe132a-c25b-40f0-93a7-7957cf978004%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/dbfe132a-c25b-40f0-93a7-7957cf978004%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: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [February 20, 2014, 5:37pm UTC](https://discuss.elastic.co/t/indexing-images/15929/2 "2014-02-20T17:37:14Z")

</div>

There is no OCR plugin. I tried to find something but did not really find anything useful: [https://github.com/elasticsearch/elasticsearch-mapper-attachments/issues/10](https://github.com/elasticsearch/elasticsearch-mapper-attachments/issues/10)

To be honest, I think it was a false good idea. I mean that doing OCR inside elasticsearch nodes does not make sense to me.  
This is something which should be done outside elasticsearch, for example in logstash if possible.

My 2 cents

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr

Le 20 février 2014 à 17:39:05, ZenMaster80 ([sabdalla80@gmail.com](mailto:sabdalla80@gmail.com)) a écrit:

I am a bit confused about this topic, I would like to index images (png,jpegs, gifs...), my understanding is that I need to extract and index text portions from images, I don't really care for the meta data. So, I looked online and decided to use apache Tika which I also use to extract text and index pdfs (pdfs work fine).

- How do I get the text part of images? All I am able to extract is metadata which I don't need.

- Ideally I want to say if this image has no text to extract, then discard/ignore? Can you please clarify this topic a bit more and provide any samples if available? Additionaly, I don't want to store the 64 based encoded document.  
PutMappingResponse putMappingResponse = new PutMappingRequestBuilder(

for(int i = 0; i \<metadata.names().length; i++) { //metaData -I don't care for this

```
   String name = metadata.names()[i];
   System.out.println(name + " : " + metadata.get(name));

 }

```

}

--  
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/dbfe132a-c25b-40f0-93a7-7957cf978004%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/dbfe132a-c25b-40f0-93a7-7957cf978004%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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/etPan.53063d4b.6763845e.3fd6%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.53063d4b.6763845e.3fd6%40MacBook-Air-de-David.local).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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: [February 20, 2014, 5:45pm UTC](https://discuss.elastic.co/t/indexing-images/15929/3 "2014-02-20T17:45:10Z")

</div>

Thanks David. I agree that OCR and maybe any kind of text extraction should  
be done pre-Elastic Search indexing. But, I am just wondering if apache  
tika supports this, or if anyone has experience with using a certain tool.  
I do plan to do extract before indexing.

On Thursday, February 20, 2014 11:38:31 AM UTC-5, ZenMaster80 wrote:

> I am a bit confused about this topic, I would like to index images  
> (png,jpegs, gifs...), my understanding is that I need to extract and index  
> text portions from images, I don't really care for the meta data. So, I  
> looked online and decided to use apache Tika which I also use to extract  
> text and index pdfs (pdfs work fine).
> 
> - How do I get the text part of images? All I am able to extract is  
> metadata which I don't need.
> - Ideally I want to say if this image has no text to extract, then  
> discard/ignore? Can you please clarify this topic a bit more and provide  
> any samples if available? Additionaly, I don't want to store the 64 based  
> encoded document.
> 
> PutMappingResponse putMappingResponse = new PutMappingRequestBuilder(
> 
> ```
> client.admin().indices() ).setIndices(
> 
> ```
> 
> INDEX\_NAME).setType(INDEX\_TYPE).setSource(  
> XContentFactory.jsonBuilder  
> ().startObject()
> 
> ```
> .startObject(INDEX_TYPE)
> 
> .startObject("_source").field(
> 
> ```
> 
> "enabled","no").endObject() //I believe this line will not store the  
> base 64 whole \_source, below I store the text portion of file only "file"
> 
> ```
> .startObject("properties")
> 
> .startObject("file")
> 
> .field( "term_vector", 
> 
> ```
> 
> "with\_positions\_offsets" )
> 
> ```
> .field( "store", "no" )
> 
> .field( "type", "attachment" )
> 
> .field("fields")
> 
> .startObject()
> 
> .startObject("file")
> 
> .field("store", "yes")
> 
> .endObject()
> 
> .endObject()
> 
> .endObject()
> 
> .endObject()
> 
> .endObject()
> 
> .endObject()
> 
> ).execute().actionGet();
> 
> public static void testImage(File file) throws IOException, 
> 
> ```
> 
> SAXException,TikaException {
> 
> ```
> Tika tika = new Tika();
> 
> InputStream inputStream = new BufferedInputStream( new 
> 
> ```
> 
> FileInputStream(file));
> 
> Metadata metadata = new Metadata();
> 
> ContentHandler handler = new DefaultHandler();
> 
> Parser parser = new JpegParser();
> 
> ParseContext context = new ParseContext();
> 
> String mimeType = tika.detect(inputStream);
> 
> ```
> metadata.set(Metadata.CONTENT_TYPE, mimeType);
> 
> ```
> 
> parser.parse(inputStream,handler,metadata,context);
> 
> for(int i = 0; i \<metadata.names().length; i++) { //metaData -I don't  
> care for this
> 
> ```
> String name = metadata.names()[i];
> System.out.println(name + " : " + metadata.get(name));
> 
> }
> 
> ```
> 
> }

--  
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/fac820d6-5343-4820-8acc-7e20c5663984%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/fac820d6-5343-4820-8acc-7e20c5663984%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:48am UTC](https://discuss.elastic.co/t/indexing-images/15929/4 "2017-07-06T01:48:35Z")

</div>


