# No hits when do a text search in an attachment for .docx file

**URL:** <https://discuss.elastic.co/t/no-hits-when-do-a-text-search-in-an-attachment-for-docx-file/41779>\
**Category:** Elasticsearch\
**Created:** [February 15, 2016, 12:14pm UTC](https://discuss.elastic.co/t/no-hits-when-do-a-text-search-in-an-attachment-for-docx-file/41779 "2016-02-15T12:14:14Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![MaryOConnor](https://avatars.discourse-cdn.com/v4/letter/m/c68b51/32.png) [@MaryOConnor](https://discuss.elastic.co/u/MaryOConnor)\
**Post date:** [February 15, 2016, 12:14pm UTC](https://discuss.elastic.co/t/no-hits-when-do-a-text-search-in-an-attachment-for-docx-file/41779/1 "2016-02-15T12:14:14Z")

</div>

Hi,

I'm new to elasticsearch. I'm using version 2.2.0 of Elasticsearch.

I am able to index a .txt file and a .doc file and do a search and get a hit.

However, when I try to index a .docx file, I do not get any hits.

My index is client\_index.

My type is documents.

This is my mapping json:

```
{
    "index":"client_index",
    "type":"documents",
    "body":{
        "documents":{
            "properties":{
                "file":{
                    "type":"attachment"
                }
            }
        }
    }
}

```

I base64 encode the contents of a .docx file and I add the document to the index with the following json:

```
{
        "index":"client_index",
        "type":"documents",
        "id":"1",
        "body":{
            "file": "' . $file_encoded . '"
        }
    }

```

This is the response that I get:

Array

```
(
    [_index] => client_index
    [_type] => documents
    [_id] => 1
    [_version] => 1
    [_shards] => Array
        (
            [total] => 2
            [successful] => 1
            [failed] => 0
        )

    [created] => 1
)

```

The content of the .docx file is simply: "This is a small test."

I do a search with the following json:

```
// Search for text in an attachment
$search_text = "test";
    
$json = '
{
    "index":"client_index",
    "type":"documents",
    "body":{
        "query":{
            "query_string":{
                "query": "' . $search_text . '"
            }
        }
    }
}

```

This is the response that I get:

```
(
    [_index] => client_index
    [_type] => documents
    [_id] => 1
    [_version] => 1
    [_shards] => Array
        (
            [total] => 2
            [successful] => 1
            [failed] => 0
        )

    [created] => 1
)

```

I'm searching for the string "test" but I get no hits.

Can someone help me with this please. Thanks.

Mary

---

<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 15, 2016, 4:14pm UTC](https://discuss.elastic.co/t/no-hits-when-do-a-text-search-in-an-attachment-for-docx-file/41779/2 "2016-02-15T16:14:11Z")

</div>

Can you check that:

- plugin is loaded
- mapping has been applied correctly

Then, can you try a `match` query on field `file.content`?

---

<div class="post-metadata">

**Author:** ![MaryOConnor](https://avatars.discourse-cdn.com/v4/letter/m/c68b51/32.png) [@MaryOConnor](https://discuss.elastic.co/u/MaryOConnor)\
**Post date:** [February 16, 2016, 10:21am UTC](https://discuss.elastic.co/t/no-hits-when-do-a-text-search-in-an-attachment-for-docx-file/41779/3 "2016-02-16T10:21:54Z")

</div>

Hi David,

Thanks for your reply and for your help with this.

I managed yesterday to get the search working for all files types except .docx files, so that probably means that the plugin is loaded and that the mapping has been applied correctly but I must be missing something as it is supposed to work with .docx files also.

This is my mapping json:

{  
"index":"client\_index",  
"type":"documents",  
"body":{  
"documents":{  
"properties":{  
"file":{  
"type":"attachment",  
"fields": {  
"content": {  
"type": "string",  
"term\_vector":"with\_positions\_offsets",  
"store": true  
}  
}  
}  
}  
}  
}  
}

and this is my index json:

{  
"index":"client\_index",  
"type":"documents",  
"id":"' . $index . '",  
"body":{  
"file":{  
"\_content":"' . $file\_encoded . '",  
"\_name":"' . $file\_to\_index .'",  
"\_content\_type":"' . $mime\_type . '",  
"\_indexed\_chars":"-1",  
"\_detect\_language":"true"  
}  
}  
}

and this is my search json:

{  
"index":"client\_index",  
"type":"documents",  
"body":{  
"query":{  
"match":{  
"file.content": "' . $search\_text . '"  
}  
},  
"highlight": {  
"fields": {  
"file.content": {  
}  
}  
}  
}  
}

Your help is much appreciated. Thanks. Mary

---

<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 17, 2016, 4:33am UTC](https://discuss.elastic.co/t/no-hits-when-do-a-text-search-in-an-attachment-for-docx-file/41779/4 "2016-02-17T04:33:54Z")

</div>

Can you share your file?

---

<div class="post-metadata">

**Author:** ![MaryOConnor](https://avatars.discourse-cdn.com/v4/letter/m/c68b51/32.png) [@MaryOConnor](https://discuss.elastic.co/u/MaryOConnor)\
**Post date:** [February 17, 2016, 11:38am UTC](https://discuss.elastic.co/t/no-hits-when-do-a-text-search-in-an-attachment-for-docx-file/41779/6 "2016-02-17T11:38:55Z")

</div>

Hi David,

Here is a link to a gist:

> <https://gist.github.com/silverarm/9657134efd9468832b7a>

Thanks for your help.

Mary

---

<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 17, 2016, 5:55pm UTC](https://discuss.elastic.co/t/no-hits-when-do-a-text-search-in-an-attachment-for-docx-file/41779/7 "2016-02-17T17:55:31Z")

</div>

I was just asking for the .docx file. Can you share it?

---

<div class="post-metadata">

**Author:** ![MaryOConnor](https://avatars.discourse-cdn.com/v4/letter/m/c68b51/32.png) [@MaryOConnor](https://discuss.elastic.co/u/MaryOConnor)\
**Post date:** [February 18, 2016, 10:14am UTC](https://discuss.elastic.co/t/no-hits-when-do-a-text-search-in-an-attachment-for-docx-file/41779/8 "2016-02-18T10:14:31Z")

</div>

Hi David,

Here is a link to the Test.docx file:

[http://silverarm.com/assets/Test.docx](http://silverarm.com/assets/Test.docx)

Thanks.

Mary

---

<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 18, 2016, 3:09pm UTC](https://discuss.elastic.co/t/no-hits-when-do-a-text-search-in-an-attachment-for-docx-file/41779/9 "2016-02-18T15:09:14Z")

</div>

I tried to extract data from your doc and it works as expected.

```auto
## Extracted text
--------------------- BEGIN -----------------------
This is a small test.

---------------------- END ------------------------
## Metadata
- author: Mary O'Connor
- content_length: 11375
- content_type: application/vnd.openxmlformats-officedocument.wordprocessingml.document
- date: 1455550860000
- keywords: null
- language: null
- name: null
- title: null

```

What is the output when you run your query?

---

<div class="post-metadata">

**Author:** ![thespatt](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thespatt/32/7979_2.png) [@thespatt](https://discuss.elastic.co/u/thespatt)\
**Post date:** [February 22, 2016, 7:40pm UTC](https://discuss.elastic.co/t/no-hits-when-do-a-text-search-in-an-attachment-for-docx-file/41779/10 "2016-02-22T19:40:22Z")

</div>

Hello, I'm having the same issue. Was using the old plugin in ES 1.7 and it worked fine, but using ES 2.2 with the new plugin i cannot search on the docx content. If I re-save the docx as Word 97-2003 doc it works perfect. Tried with several different documents.

---

<div class="post-metadata">

**Author:** ![dvaneynde](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dvaneynde/32/8177_2.png) [@dvaneynde](https://discuss.elastic.co/u/dvaneynde)\
**Post date:** [February 29, 2016, 4:17pm UTC](https://discuss.elastic.co/t/no-hits-when-do-a-text-search-in-an-attachment-for-docx-file/41779/11 "2016-02-29T16:17:45Z")

</div>

Same issue here, works with Text of PDF, but not with the Office formats. I tried with a small Word document, and this is what I see in the logs:

[2016-02-29 16:43:39,341][DEBUG][mapper.attachment] Failed to extract [100000] characters of text for [null]: [Unexpected RuntimeExceptio  
n from org.apache.tika.parser.microsoft.ooxml.OOXMLParser@51667d8a]  
...  
Caused by: java.lang.IllegalStateException: access denied ("java.lang.RuntimePermission" "getClassLoader")  
at org.apache.xmlbeans.XmlBeans.getContextTypeLoader(XmlBeans.java:336)  
...  
Caused by: java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "getClassLoader")  
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)

---

<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 29, 2016, 4:38pm UTC](https://discuss.elastic.co/t/no-hits-when-do-a-text-search-in-an-attachment-for-docx-file/41779/12 "2016-02-29T16:38:02Z")

</div>

Thanks @dvaneynde and others. Very helpful.

I opened [https://github.com/elastic/elasticsearch/issues/16864](https://github.com/elastic/elasticsearch/issues/16864) to track this.

---

<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 5, 2017, 11:12pm UTC](https://discuss.elastic.co/t/no-hits-when-do-a-text-search-in-an-attachment-for-docx-file/41779/13 "2017-07-05T23:12:49Z")

</div>


