# Search problem within the attachment type field

**URL:** <https://discuss.elastic.co/t/search-problem-within-the-attachment-type-field/41700>\
**Category:** Elasticsearch\
**Created:** [February 13, 2016, 9:43pm UTC](https://discuss.elastic.co/t/search-problem-within-the-attachment-type-field/41700 "2016-02-13T21:43:39Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ferhat\_Ozturk](https://avatars.discourse-cdn.com/v4/letter/f/4af34b/32.png) [@Ferhat\_Ozturk](https://discuss.elastic.co/u/Ferhat_Ozturk)\
**Post date:** [February 13, 2016, 9:43pm UTC](https://discuss.elastic.co/t/search-problem-within-the-attachment-type-field/41700/1 "2016-02-13T21:43:39Z")

</div>

Hello,  
First of all, let me tell you that i am totally new on elasticsearch concept and trying to learn it in details.  
Now, i am having a problem about searching on an attachment field (I can query on other fields)

This is my mapping:  
{  
"files": {  
"properties": {  
"file": {  
"type": "attachment",  
"fields": {  
"content": {  
"type": "string",  
"term\_vector":"with\_positions\_offsets",  
"store": true  
},  
"name" : { "type" : "string" }  
}  
}  
}  
}  
}

This is the result when i query with the record id ([http://localhost:9200/filesystem/files/10](http://localhost:9200/filesystem/files/10)):  
{  
"\_index": "filesystem",  
"\_type": "files",  
"\_id": "10",  
"\_version": 1,  
"found": true,  
"\_source": {  
"content": "e1xydGYxXGFuc2kNCkxvcmVtIGlwc3VtIGRvbG9yIHNpdCBhbWV0DQpccGFyIH0="  
}  
}

Encoded string contains "ipsum" word so i should be able to get a result when i query "ipsum".

I could not get any result with below one through REST client:  
POST [http://localhost:9200/filesystem/files/\_search](http://localhost:9200/filesystem/files/_search)  
{  
"query": {  
"query\_string": {  
"query": "ipsum"  
}}}

can you pls help me how can i search within the attachment type field.  
Thanks in advance

---

<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 13, 2016, 10:49pm UTC](https://discuss.elastic.co/t/search-problem-within-the-attachment-type-field/41700/2 "2016-02-13T22:49:45Z")

</div>

Your field name should be file. Not content.

---

<div class="post-metadata">

**Author:** ![Ferhat\_Ozturk](https://avatars.discourse-cdn.com/v4/letter/f/4af34b/32.png) [@Ferhat\_Ozturk](https://discuss.elastic.co/u/Ferhat_Ozturk)\
**Post date:** [February 14, 2016, 4:32pm UTC](https://discuss.elastic.co/t/search-problem-within-the-attachment-type-field/41700/4 "2016-02-14T16:32:22Z")

</div>

Hello David,  
thanks for your reply, it solved one part of my problem, i appreciate it.  
Now i have another problem about highlighting the result. can you pls help me about this too?

## My mapping:

{  
"files": {  
"properties": {  
"file": {  
"type": "attachment",  
"fields": {  
"content": {  
"type": "string",  
"term\_vector":"with\_positions\_offsets",  
"store": true  
},  
"name" : { "type" : "string" }  
}  
}  
}  
}  
}

## My Insert Document Request:

{  
"file" : "e1xydGYxXGFuc2kNCkxvcmVtIGlwc3VtIGRvbG9yIHNpdCBhbWV0DQpccGFyIH0="  
}

## My Query Request:

{  
"query": {  
"query\_string": {  
"query": "ipsum"  
}  
},  
"highlight" : {  
"fields" : {  
"file" : {}  
}  
}  
}

## The Search Result:

{  
"took": 4,  
"timed\_out": false,  
"\_shards": {  
"total": 5,  
"successful": 5,  
"failed": 0  
},  
"hits": {  
"total": 1,  
"max\_score": 0.095891505,  
"hits": [  
{  
"\_index": "filesystem",  
"\_type": "files",  
"\_id": "11",  
"\_score": 0.095891505,  
"\_source": {  
"file": "e1xydGYxXGFuc2kNCkxvcmVtIGlwc3VtIGRvbG9yIHNpdCBhbWV0DQpccGFyIH0="  
}  
}  
]  
}  
}

As you can see in the response, there is no hightlight information in the response. What is my mistake, pls kindly advice.  
Thanks

---

<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 14, 2016, 4:50pm UTC](https://discuss.elastic.co/t/search-problem-within-the-attachment-type-field/41700/5 "2016-02-14T16:50:41Z")

</div>

Have a look at [https://www.elastic.co/guide/en/elasticsearch/plugins/current/mapper-attachments-highlighting.html](https://www.elastic.co/guide/en/elasticsearch/plugins/current/mapper-attachments-highlighting.html)

Highlight `file.content`

---

<div class="post-metadata">

**Author:** ![Ferhat\_Ozturk](https://avatars.discourse-cdn.com/v4/letter/f/4af34b/32.png) [@Ferhat\_Ozturk](https://discuss.elastic.co/u/Ferhat_Ozturk)\
**Post date:** [February 14, 2016, 5:02pm UTC](https://discuss.elastic.co/t/search-problem-within-the-attachment-type-field/41700/6 "2016-02-14T17:02:10Z")

</div>

when i query with "match", i can get the highlighted result. however when i use the "query\_string", i can not get the highlighted result. what is the difference between them. I am asking this in order to learn it in details, thanks for your time .

## this works for highlighting:

request:  
{  
"query": {  
"match": {  
"file.content": "ipsum"  
}  
},  
"highlight" : {  
"fields" : {  
"file.content" : {}  
}  
}  
}  
response:  
{  
"took": 6,  
"timed\_out": false,  
"\_shards": {  
"total": 5,  
"successful": 5,  
"failed": 0  
},  
"hits": {  
"total": 1,  
"max\_score": 0.13424811,  
"hits": [  
{  
"\_index": "filesystem",  
"\_type": "files",  
"\_id": "11",  
"\_score": 0.13424811,  
"\_source": {  
"file": "e1xydGYxXGFuc2kNCkxvcmVtIGlwc3VtIGRvbG9yIHNpdCBhbWV0DQpccGFyIH0="  
},  
"highlight": {  
"file.content": [  
"Lorem _ipsum_ dolor sit amet\n\n"  
]  
}  
}  
]  
}  
}

## this does not works for highlighting:

request:  
{  
"query": {  
"query\_string": {  
"query": "ipsum"  
}  
},  
"highlight" : {  
"fields" : {  
"file.content" : {}  
}  
}  
}  
response:  
{  
"took": 5,  
"timed\_out": false,  
"\_shards": {  
"total": 5,  
"successful": 5,  
"failed": 0  
},  
"hits": {  
"total": 1,  
"max\_score": 0.095891505,  
"hits": [  
{  
"\_index": "filesystem",  
"\_type": "files",  
"\_id": "11",  
"\_score": 0.095891505,  
"\_source": {  
"file": "e1xydGYxXGFuc2kNCkxvcmVtIGlwc3VtIGRvbG9yIHNpdCBhbWV0DQpccGFyIH0="  
}  
}  
]  
}  
}

---

<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 14, 2016, 5:18pm UTC](https://discuss.elastic.co/t/search-problem-within-the-attachment-type-field/41700/7 "2016-02-14T17:18:27Z")

</div>

query\_string query uses \_all field. That's the reason.

---

<div class="post-metadata">

**Author:** ![Ferhat\_Ozturk](https://avatars.discourse-cdn.com/v4/letter/f/4af34b/32.png) [@Ferhat\_Ozturk](https://discuss.elastic.co/u/Ferhat_Ozturk)\
**Post date:** [February 15, 2016, 8:42pm UTC](https://discuss.elastic.co/t/search-problem-within-the-attachment-type-field/41700/8 "2016-02-15T20:42:31Z")

</div>

Hello David,  
Now, i have another problem, i have indexed a word document (docx) which is a CV and mostly prepared with tables in the document, but i am not able to find results with basic searchs.  
Is there a restriction about the tables in elastic search? do you have any idea about my problem?  
thank you

This is the screenshot of the document which i have indexed.

![](https://us1.discourse-cdn.com/elastic/original/2X/8/8a07f88f2a62ccf0101ee83a9ac76da102c252a2.png)

---

<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, 9:29pm UTC](https://discuss.elastic.co/t/search-problem-within-the-attachment-type-field/41700/9 "2016-02-15T21:29:39Z")

</div>

Well. I don't know. It depends on what Tika can do as this plugin only exposes Tika.

---

<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:16pm UTC](https://discuss.elastic.co/t/search-problem-within-the-attachment-type-field/41700/10 "2017-07-05T23:16:13Z")

</div>


