# Attachment highlighting while excluding from source?

**URL:** <https://discuss.elastic.co/t/attachment-highlighting-while-excluding-from-source/7495>\
**Category:** Elasticsearch\
**Created:** [April 27, 2012, 2:22pm UTC](https://discuss.elastic.co/t/attachment-highlighting-while-excluding-from-source/7495 "2012-04-27T14:22:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shane\_Witbeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shane_witbeck/32/2803_2.png) [@Shane\_Witbeck](https://discuss.elastic.co/u/Shane_Witbeck)\
**Post date:** [April 27, 2012, 2:22pm UTC](https://discuss.elastic.co/t/attachment-highlighting-while-excluding-from-source/7495/1 "2012-04-27T14:22:53Z")

</div>

I've resorted to excluding attachment content to prevent the content of the  
indexed files from being included as part of search results.

Is it still possible to do highlighting for the file contents? My initial  
testing tells me no but I'm wondering if I'm missing something.

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [April 29, 2012, 4:50pm UTC](https://discuss.elastic.co/t/attachment-highlighting-while-excluding-from-source/7495/2 "2012-04-29T16:50:11Z")

</div>

You mean you excluded it so it won't be returned when you get back \_source?  
You can two options:

1. Use partials in search request, to exclude the attachment, and still  
store the full source.  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/fields.html) (see  
under partial). Note, this will still load the \_source and parse it, and  
then exclude the attachment part.
2. Exclude the attachment from \_source in the mapping, but mark it as  
stored (store set to yet) in the mapping. Then, it will be stored "on its  
own" separate from \_source.

On Fri, Apr 27, 2012 at 5:22 PM, Shane Witbeck [shane@digitalsanctum.com](mailto:shane@digitalsanctum.com)wrote:

> I've resorted to excluding attachment content to prevent the content of  
> the indexed files from being included as part of search results.
> 
> Is it still possible to do highlighting for the file contents? My initial  
> testing tells me no but I'm wondering if I'm missing something.

---

<div class="post-metadata">

**Author:** ![Shane\_Witbeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shane_witbeck/32/2803_2.png) [@Shane\_Witbeck](https://discuss.elastic.co/u/Shane_Witbeck)\
**Post date:** [May 2, 2012, 1:34pm UTC](https://discuss.elastic.co/t/attachment-highlighting-while-excluding-from-source/7495/3 "2012-05-02T13:34:10Z")

</div>

Thanks Shay. I went with #2 and it works great.

On Sunday, April 29, 2012 12:50:11 PM UTC-4, kimchy wrote:

> You mean you excluded it so it won't be returned when you get back  
> \_source? You can two options:
> 
> 1. Use partials in search request, to exclude the attachment, and still  
> store the full source.  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/fields.html) (see  
> under partial). Note, this will still load the \_source and parse it, and  
> then exclude the attachment part.
> 2. Exclude the attachment from \_source in the mapping, but mark it as  
> stored (store set to yet) in the mapping. Then, it will be stored "on its  
> own" separate from \_source.
> 
> On Fri, Apr 27, 2012 at 5:22 PM, Shane Witbeck [shane@digitalsanctum.com](mailto:shane@digitalsanctum.com)wrote:
> 
> > I've resorted to excluding attachment content to prevent the content of  
> > the indexed files from being included as part of search results.
> > 
> > Is it still possible to do highlighting for the file contents? My initial  
> > testing tells me no but I'm wondering if I'm missing something.

---

<div class="post-metadata">

**Author:** ![tuan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tuan/32/2759_2.png) [@tuan](https://discuss.elastic.co/u/tuan)\
**Post date:** [August 16, 2012, 6:11pm UTC](https://discuss.elastic.co/t/attachment-highlighting-while-excluding-from-source/7495/4 "2012-08-16T18:11:34Z")

</div>

#2 does not work for me. I could not figure out what I doing wrong here. Please help !  
Here's my mapping:

mapping :\_source =\> { :excludes =\> ['attachment\_original'] } do  
indexes :id, :type =\> 'integer'  
indexes :folder\_id, :type =\> 'integer'  
indexes :attachment\_file\_name  
indexes :attachment\_updated\_at, :type =\> 'date'  
indexes :attachment\_original, :type =\> 'attachment',  
:fields =\> {:title =\> {:store =\> "yes"},  
:attachment\_original =\> {:term\_vector =\> "with\_positions\_offsets", :store =\> "yes"}}

end

def to\_indexed\_json  
to\_json(:methods =\> [:attachment\_original])  
end

the curl command that is generated :

curl -X GET "[http://localhost:9200/user\_files/user\_file/\_search?pretty=true](http://localhost:9200/user_files/user_file/_search?pretty=true)" -d '{"query":{"query\_string":{"query":"rspec","default\_operator":"AND"}},"filter":{"term":{"folder\_id":1}},"highlight":{"fields":{"attachment\_original":{}}}}'

the search works find, but the attachement file is included in the search results as seen here:

"\_source" : {"user\_file":{"id":5,"folder\_id":1,"updated\_at":"2012-08-16T11:32:41Z","attachment\_file\_size":179895,"attachment\_updated\_at":"2012-08-16T11:32:41Z","attachment\_file\_name":"hw4.pdf","attachment\_content\_type":"application/pdf","created\_at":"2012-08-16T11:32:41Z","attachment\_original":"JVBERi0xL .....

--  
Tuan

Thanks Shay. I went with #2 and it works great.

On Sunday, April 29, 2012 12:50:11 PM UTC-4, kimchy wrote:

> You mean you excluded it so it won't be returned when you get back  
> \_source? You can two options:
> 
> 1. Use partials in search request, to exclude the attachment, and still  
> store the full source.  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/fields.html) (see  
> under partial). Note, this will still load the \_source and parse it, and  
> then exclude the attachment part.
> 2. Exclude the attachment from \_source in the mapping, but mark it as  
> stored (store set to yet) in the mapping. Then, it will be stored "on its  
> own" separate from \_source.
> 
> On Fri, Apr 27, 2012 at 5:22 PM, Shane Witbeck \<shane@\>wrote:
> 
> > I've resorted to excluding attachment content to prevent the content of  
> > the indexed files from being included as part of search results.
> > 
> > Is it still possible to do highlighting for the file contents? My initial  
> > testing tells me no but I'm wondering if I'm missing something.

---

<div class="post-metadata">

**Author:** ![tuan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tuan/32/2759_2.png) [@tuan](https://discuss.elastic.co/u/tuan)\
**Post date:** [August 16, 2012, 6:15pm UTC](https://discuss.elastic.co/t/attachment-highlighting-while-excluding-from-source/7495/5 "2012-08-16T18:15:07Z")

</div>

#2 does not work for me. I could not figure out what I doing wrong here.  
Please help !  
Here's my mapping:

mapping :\_source =\> { :excludes =\> ['attachment\_original'] } do  
indexes :id, :type =\> 'integer'  
indexes :folder\_id, :type =\> 'integer'  
indexes :attachment\_file\_name  
indexes :attachment\_updated\_at, :type =\> 'date'  
indexes :attachment\_original, :type =\> 'attachment',  
:fields =\> {:title =\> {:store =\> "yes"},  
:attachment\_original =\> {:term\_vector =\>  
"with\_positions\_offsets", :store =\> "yes"}}

end

def to\_indexed\_json  
to\_json(:methods =\> [:attachment\_original])  
end

the curl command that is generated :

curl -X GET "[http://localhost:9200/user\_files/user\_file/\_search?pretty=true](http://localhost:9200/user_files/user_file/_search?pretty=true)"  
-d  
'{"query":{"query\_string":{"query":"rspec","default\_operator":"AND"}},"filter":{"term":{"folder\_id":1}},"highlight":{"fields":{"attachment\_original":{}}}}'

the search works find, but the attachement file is included in the search  
results as seen here:

"\_source" : {"user\_file":{"id":5,"folder\_id":1,"updated\_at":  
"2012-08-16T11:32:41Z","attachment\_file\_size":179895,"attachment\_updated\_at"  
:"2012-08-16T11:32:41Z","attachment\_file\_name":"hw4.pdf",  
"attachment\_content\_type":"application/pdf","created\_at":  
"2012-08-16T11:32:41Z","attachment\_original":"JVBERi0xL .....

--  
Tuan

On Wednesday, May 2, 2012 8:34:10 PM UTC+7, Shane Witbeck wrote:

> Thanks Shay. I went with #2 and it works great.
> 
> On Sunday, April 29, 2012 12:50:11 PM UTC-4, kimchy wrote:
> 
> > You mean you excluded it so it won't be returned when you get back  
> > \_source? You can two options:
> > 
> > 1. Use partials in search request, to exclude the attachment, and still  
> > store the full source.  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/fields.html) (see  
> > under partial). Note, this will still load the \_source and parse it, and  
> > then exclude the attachment part.
> > 2. Exclude the attachment from \_source in the mapping, but mark it as  
> > stored (store set to yet) in the mapping. Then, it will be stored "on its  
> > own" separate from \_source.
> > 
> > On Fri, Apr 27, 2012 at 5:22 PM, Shane Witbeck \<[sh...@digitalsanctum.com](mailto:sh...@digitalsanctum.com)\<javascript:\>
> > 
> > > wrote:
> > 
> > > I've resorted to excluding attachment content to prevent the content of  
> > > the indexed files from being included as part of search results.
> > > 
> > > Is it still possible to do highlighting for the file contents? My  
> > > initial testing tells me no but I'm wondering if I'm missing something.

--

---

<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, 3:16am UTC](https://discuss.elastic.co/t/attachment-highlighting-while-excluding-from-source/7495/6 "2017-07-06T03:16:08Z")

</div>


