# How can we index array of attachments

**URL:** <https://discuss.elastic.co/t/how-can-we-index-array-of-attachments/19499>\
**Category:** Elasticsearch\
**Created:** [August 27, 2014, 4:27pm UTC](https://discuss.elastic.co/t/how-can-we-index-array-of-attachments/19499 "2014-08-27T16:27:37Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![sekharreddy\_mandapat](https://avatars.discourse-cdn.com/v4/letter/s/c4cdca/32.png) [@sekharreddy\_mandapat](https://discuss.elastic.co/u/sekharreddy_mandapat)\
**Post date:** [August 27, 2014, 4:27pm UTC](https://discuss.elastic.co/t/how-can-we-index-array-of-attachments/19499/1 "2014-08-27T16:27:37Z")

</div>

We have requirement of indexing email which have multiple attachments and  
we have to highlight the search results. How can i map the highlight string  
array to my multiple attachments.

My index mapping is

{  
"document":{  
"properties":{  
"attachmentContent":{  
"type":"attachment",  
"path":"full",  
"fields":{  
"attachmentContent":{  
"type":"string",  
"term\_vector":"with\_positions\_offsets",  
"store":true  
}  
}  
}  
}  
}  
}

My indexed document is

{"userId":2,"attachmentContent":[{"content":"VGhpcyBpcyBudW1iZXIgb25lLg==","serviceAttachmentId":"1","fileName":"1.txt","type":"xml"},  
{  
{"content":"IkdvZCBTYXZlIHRoZSBRdWVlbiIgKGFsdGVybmF0aXZlbHkgIkdvZCBTYXZlIHRoZSBLaW5nIg==","serviceAttachmentId":"2","fileName":"2.txt","type":"excel"}]

}

My Questions are

1.How can i access the "serviceAttachmentId" inside the "attachmentContent"  
field which is of type attachment.  
2.How can i filter the documents based on type.

--  
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/1c34c96f-c28f-4d4f-8c09-970160f9e669%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1c34c96f-c28f-4d4f-8c09-970160f9e669%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [August 27, 2014, 4:37pm UTC](https://discuss.elastic.co/t/how-can-we-index-array-of-attachments/19499/2 "2014-08-27T16:37:44Z")

</div>

You can't add your own subfields to the attachment field.  
Though this should be doable but requires some work IMO.

Also, I think you need to use nested documents. And add whatever field you want in the nested doc (type, id...) and add the attachment field as well.

HTH

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 27 août 2014 à 18:27, sekharreddy mandapati [sekhar4233@gmail.com](mailto:sekhar4233@gmail.com) a écrit :

We have requirement of indexing email which have multiple attachments and we have to highlight the search results. How can i map the highlight string array to my multiple attachments.

My index mapping is

{  
"document":{  
"properties":{  
"attachmentContent":{  
"type":"attachment",  
"path":"full",  
"fields":{  
"attachmentContent":{  
"type":"string",  
"term\_vector":"with\_positions\_offsets",  
"store":true  
}  
}  
}  
}  
}  
}

My indexed document is

{"userId":2,"attachmentContent":[{"content":"VGhpcyBpcyBudW1iZXIgb25lLg==","serviceAttachmentId":"1","fileName":"1.txt","type":"xml"},  
{ {"content":"IkdvZCBTYXZlIHRoZSBRdWVlbiIgKGFsdGVybmF0aXZlbHkgIkdvZCBTYXZlIHRoZSBLaW5nIg==","serviceAttachmentId":"2","fileName":"2.txt","type":"excel"}]

}

My Questions are

1.How can i access the "serviceAttachmentId" inside the "attachmentContent" field which is of type attachment.  
2.How can i filter the documents based on type.

--  
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/1c34c96f-c28f-4d4f-8c09-970160f9e669%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1c34c96f-c28f-4d4f-8c09-970160f9e669%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/D5451799-32E1-484D-9F78-F016CEA172FB%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/D5451799-32E1-484D-9F78-F016CEA172FB%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![sekharreddy\_mandapat](https://avatars.discourse-cdn.com/v4/letter/s/c4cdca/32.png) [@sekharreddy\_mandapat](https://discuss.elastic.co/u/sekharreddy_mandapat)\
**Post date:** [August 27, 2014, 4:47pm UTC](https://discuss.elastic.co/t/how-can-we-index-array-of-attachments/19499/3 "2014-08-27T16:47:22Z")

</div>

Thanks David,

I am using the following mapping. Can u please tell me the mapping for  
nested documents.

{  
"document":{  
"properties":{  
"attachmentContent":{  
"type":"attachment",  
"path":"full",  
"fields":{  
"attachmentContent":{  
"type":"string",  
"term\_vector":"with\_positions\_offsets",  
"store":true  
}  
}  
}  
}  
}  
}

On Wednesday, 27 August 2014 22:08:29 UTC+5:30, David Pilato wrote:

> You can't add your own subfields to the attachment field.  
> Though this should be doable but requires some work IMO.
> 
> Also, I think you need to use nested documents. And add whatever field you  
> want in the nested doc (type, id...) and add the attachment field as well.
> 
> HTH
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 27 août 2014 à 18:27, sekharreddy mandapati \<[sekha...@gmail.com](mailto:sekha...@gmail.com)  
> \<javascript:\>\> a écrit :
> 
> We have requirement of indexing email which have multiple attachments and  
> we have to highlight the search results. How can i map the highlight string  
> array to my multiple attachments.
> 
> My index mapping is
> 
> {  
> "document":{  
> "properties":{  
> "attachmentContent":{  
> "type":"attachment",  
> "path":"full",  
> "fields":{  
> "attachmentContent":{  
> "type":"string",  
> "term\_vector":"with\_positions\_offsets",  
> "store":true  
> }  
> }  
> }  
> }  
> }  
> }
> 
> My indexed document is
> 
> {"userId":2,"attachmentContent":[{"content":"VGhpcyBpcyBudW1iZXIgb25lLg==","serviceAttachmentId":"1","fileName":"1.txt","type":"xml"},  
> {  
> {"content":"IkdvZCBTYXZlIHRoZSBRdWVlbiIgKGFsdGVybmF0aXZlbHkgIkdvZCBTYXZlIHRoZSBLaW5nIg==","serviceAttachmentId":"2","fileName":"2.txt","type":"excel"}]
> 
> }
> 
> My Questions are
> 
> 1.How can i access the "serviceAttachmentId" inside the  
> "attachmentContent" field which is of type attachment.  
> 2.How can i filter the documents based on type.
> 
> --  
> 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/1c34c96f-c28f-4d4f-8c09-970160f9e669%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1c34c96f-c28f-4d4f-8c09-970160f9e669%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/1c34c96f-c28f-4d4f-8c09-970160f9e669%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/1c34c96f-c28f-4d4f-8c09-970160f9e669%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/6c2f3651-9179-4186-92cd-89315d0ae53b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/6c2f3651-9179-4186-92cd-89315d0ae53b%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![sekharreddy\_mandapat](https://avatars.discourse-cdn.com/v4/letter/s/c4cdca/32.png) [@sekharreddy\_mandapat](https://discuss.elastic.co/u/sekharreddy_mandapat)\
**Post date:** [August 27, 2014, 5:08pm UTC](https://discuss.elastic.co/t/how-can-we-index-array-of-attachments/19499/4 "2014-08-27T17:08:30Z")

</div>

An email contain multiple attachments. This number is not fixed. How can we  
define nested documents if we our things are dynamic.

On Wednesday, 27 August 2014 22:17:23 UTC+5:30, sekharreddy mandapati wrote:

> Thanks David,
> 
> I am using the following mapping. Can u please tell me the mapping for  
> nested documents.
> 
> {  
> "document":{  
> "properties":{  
> "attachmentContent":{  
> "type":"attachment",  
> "path":"full",  
> "fields":{  
> "attachmentContent":{  
> "type":"string",  
> "term\_vector":"with\_positions\_offsets",  
> "store":true  
> }  
> }  
> }  
> }  
> }  
> }
> 
> On Wednesday, 27 August 2014 22:08:29 UTC+5:30, David Pilato wrote:
> 
> > You can't add your own subfields to the attachment field.  
> > Though this should be doable but requires some work IMO.
> > 
> > Also, I think you need to use nested documents. And add whatever field  
> > you want in the nested doc (type, id...) and add the attachment field as  
> > well.
> > 
> > HTH
> > 
> > --  
> > David 😉  
> > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > 
> > Le 27 août 2014 à 18:27, sekharreddy mandapati [sekha...@gmail.com](mailto:sekha...@gmail.com) a  
> > écrit :
> > 
> > We have requirement of indexing email which have multiple attachments and  
> > we have to highlight the search results. How can i map the highlight string  
> > array to my multiple attachments.
> > 
> > My index mapping is
> > 
> > {  
> > "document":{  
> > "properties":{  
> > "attachmentContent":{  
> > "type":"attachment",  
> > "path":"full",  
> > "fields":{  
> > "attachmentContent":{  
> > "type":"string",  
> > "term\_vector":"with\_positions\_offsets",  
> > "store":true  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }
> > 
> > My indexed document is
> > 
> > {"userId":2,"attachmentContent":[{"content":"VGhpcyBpcyBudW1iZXIgb25lLg==","serviceAttachmentId":"1","fileName":"1.txt","type":"xml"},  
> > {  
> > {"content":"IkdvZCBTYXZlIHRoZSBRdWVlbiIgKGFsdGVybmF0aXZlbHkgIkdvZCBTYXZlIHRoZSBLaW5nIg==","serviceAttachmentId":"2","fileName":"2.txt","type":"excel"}]
> > 
> > }
> > 
> > My Questions are
> > 
> > 1.How can i access the "serviceAttachmentId" inside the  
> > "attachmentContent" field which is of type attachment.  
> > 2.How can i filter the documents based on type.
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/1c34c96f-c28f-4d4f-8c09-970160f9e669%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1c34c96f-c28f-4d4f-8c09-970160f9e669%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/1c34c96f-c28f-4d4f-8c09-970160f9e669%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/1c34c96f-c28f-4d4f-8c09-970160f9e669%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/bc509a84-aba2-47b6-a943-4221412be214%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/bc509a84-aba2-47b6-a943-4221412be214%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [August 27, 2014, 6:07pm UTC](https://discuss.elastic.co/t/how-can-we-index-array-of-attachments/19499/5 "2014-08-27T18:07:07Z")

</div>

I was talking about this: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-nested-type.html)

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

> Le 27 août 2014 à 19:08, sekharreddy mandapati [sekhar4233@gmail.com](mailto:sekhar4233@gmail.com) a écrit :
> 
> An email contain multiple attachments. This number is not fixed. How can we define nested documents if we our things are dynamic.
> 
> > On Wednesday, 27 August 2014 22:17:23 UTC+5:30, sekharreddy mandapati wrote:  
> > Thanks David,
> > 
> > I am using the following mapping. Can u please tell me the mapping for nested documents.
> > 
> > {  
> > "document":{  
> > "properties":{  
> > "attachmentContent":{  
> > "type":"attachment",  
> > "path":"full",  
> > "fields":{  
> > "attachmentContent":{  
> > "type":"string",  
> > "term\_vector":"with\_positions\_offsets",  
> > "store":true  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }
> > 
> > > On Wednesday, 27 August 2014 22:08:29 UTC+5:30, David Pilato wrote:  
> > > You can't add your own subfields to the attachment field.  
> > > Though this should be doable but requires some work IMO.
> > > 
> > > Also, I think you need to use nested documents. And add whatever field you want in the nested doc (type, id...) and add the attachment field as well.
> > > 
> > > HTH
> > > 
> > > --  
> > > David 😉  
> > > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > > 
> > > Le 27 août 2014 à 18:27, sekharreddy mandapati [sekha...@gmail.com](mailto:sekha...@gmail.com) a écrit :
> > > 
> > > We have requirement of indexing email which have multiple attachments and we have to highlight the search results. How can i map the highlight string array to my multiple attachments.
> > > 
> > > My index mapping is
> > > 
> > > {  
> > > "document":{  
> > > "properties":{  
> > > "attachmentContent":{  
> > > "type":"attachment",  
> > > "path":"full",  
> > > "fields":{  
> > > "attachmentContent":{  
> > > "type":"string",  
> > > "term\_vector":"with\_positions\_offsets",  
> > > "store":true  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }
> > > 
> > > My indexed document is
> > > 
> > > {"userId":2,"attachmentContent":[{"content":"VGhpcyBpcyBudW1iZXIgb25lLg==","serviceAttachmentId":"1","fileName":"1.txt","type":"xml"},  
> > > { {"content":"IkdvZCBTYXZlIHRoZSBRdWVlbiIgKGFsdGVybmF0aXZlbHkgIkdvZCBTYXZlIHRoZSBLaW5nIg==","serviceAttachmentId":"2","fileName":"2.txt","type":"excel"}]
> > > 
> > > }
> > > 
> > > My Questions are
> > > 
> > > 1.How can i access the "serviceAttachmentId" inside the "attachmentContent" field which is of type attachment.  
> > > 2.How can i filter the documents based on type.
> > > 
> > > --  
> > > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/1c34c96f-c28f-4d4f-8c09-970160f9e669%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1c34c96f-c28f-4d4f-8c09-970160f9e669%40googlegroups.com).  
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> 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/bc509a84-aba2-47b6-a943-4221412be214%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/bc509a84-aba2-47b6-a943-4221412be214%40googlegroups.com).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/E8BDE0CC-7E8C-4162-AC29-1E8C8CDDC2C1%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/E8BDE0CC-7E8C-4162-AC29-1E8C8CDDC2C1%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![sekharreddy\_mandapat](https://avatars.discourse-cdn.com/v4/letter/s/c4cdca/32.png) [@sekharreddy\_mandapat](https://discuss.elastic.co/u/sekharreddy_mandapat)\
**Post date:** [August 27, 2014, 6:16pm UTC](https://discuss.elastic.co/t/how-can-we-index-array-of-attachments/19499/6 "2014-08-27T18:16:13Z")

</div>

I undestood how nested types work. But highlighting is not working with  
nested types.

On Wednesday, 27 August 2014 22:08:29 UTC+5:30, David Pilato wrote:

> You can't add your own subfields to the attachment field.  
> Though this should be doable but requires some work IMO.
> 
> Also, I think you need to use nested documents. And add whatever field you  
> want in the nested doc (type, id...) and add the attachment field as well.
> 
> HTH
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 27 août 2014 à 18:27, sekharreddy mandapati \<[sekha...@gmail.com](mailto:sekha...@gmail.com)  
> \<javascript:\>\> a écrit :
> 
> We have requirement of indexing email which have multiple attachments and  
> we have to highlight the search results. How can i map the highlight string  
> array to my multiple attachments.
> 
> My index mapping is
> 
> {  
> "document":{  
> "properties":{  
> "attachmentContent":{  
> "type":"attachment",  
> "path":"full",  
> "fields":{  
> "attachmentContent":{  
> "type":"string",  
> "term\_vector":"with\_positions\_offsets",  
> "store":true  
> }  
> }  
> }  
> }  
> }  
> }
> 
> My indexed document is
> 
> {"userId":2,"attachmentContent":[{"content":"VGhpcyBpcyBudW1iZXIgb25lLg==","serviceAttachmentId":"1","fileName":"1.txt","type":"xml"},  
> {  
> {"content":"IkdvZCBTYXZlIHRoZSBRdWVlbiIgKGFsdGVybmF0aXZlbHkgIkdvZCBTYXZlIHRoZSBLaW5nIg==","serviceAttachmentId":"2","fileName":"2.txt","type":"excel"}]
> 
> }
> 
> My Questions are
> 
> 1.How can i access the "serviceAttachmentId" inside the  
> "attachmentContent" field which is of type attachment.  
> 2.How can i filter the documents based on type.
> 
> --  
> 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/1c34c96f-c28f-4d4f-8c09-970160f9e669%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1c34c96f-c28f-4d4f-8c09-970160f9e669%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/1c34c96f-c28f-4d4f-8c09-970160f9e669%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/1c34c96f-c28f-4d4f-8c09-970160f9e669%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/491fba77-6c59-48e7-aef6-ac63c8d59b55%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/491fba77-6c59-48e7-aef6-ac63c8d59b55%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![sekharreddy\_mandapat](https://avatars.discourse-cdn.com/v4/letter/s/c4cdca/32.png) [@sekharreddy\_mandapat](https://discuss.elastic.co/u/sekharreddy_mandapat)\
**Post date:** [August 27, 2014, 6:31pm UTC](https://discuss.elastic.co/t/how-can-we-index-array-of-attachments/19499/7 "2014-08-27T18:31:35Z")

</div>

DELETE abc

POST abc

POST abc/mail/\_mapping  
{  
"mail" : {  
"properties" : {  
"attachments" : {  
"type" : "nested",  
"include\_in\_parent": true,  
"properties": {  
"attachmentContent":{  
"type":"attachment",  
"path":"full",  
"fields":{  
"attachmentContent":{  
"type":"string",  
"term\_vector":"with\_positions\_offsets",  
"store":true  
}  
}  
},  
"file\_name":{  
"type":"string",  
"index": "not\_analyzed"  
},  
"sharewith":{  
"type":"string",  
"index": "not\_analyzed"  
}  
}  
},  
"from": {  
"type": "string",  
"index": "not\_analyzed"  
},  
"body": {  
"type": "string"  
}  
}  
}  
}

GET abc/mail/\_mapping

POST abc/mail/1  
{  
"[from":"bala@mactores.com](mailto:from%22:%22bala@mactores.com)",  
"body":"this is simple mail from bala krishna heroor",  
"attachments":[  
{  
"attachmentContent":"VGhpcyBpcyBudW1iZXIgb25lLg==",  
"file\_name":"1.txt",  
"[sharewith":"sekhar4233@gmail.com](mailto:sharewith%22:%22sekhar4233@gmail.com)"  
},  
{  
"attachmentContent":"VGhpcyBpcyBudW1iZXIgdHdv",  
"file\_name":"2.txt",  
"[sharewith":"chetan@gmail.com](mailto:sharewith%22:%22chetan@gmail.com)"  
}  
]  
}

POST abc/mail/\_search  
{  
"fields": [  
"attachments.attachmentContent",  
"attachments.file\_name",  
"attachments.sharewith",  
"from",  
"body"  
],  
"highlight" : { "fields" : { "attachments.attachmentContent" : {} } },  
"query": {  
"nested": {  
"path": "attachments",  
"query": {  
"query\_string": {  
"default\_field": "attachments.attachmentContent",  
"query": "number"  
}  
}  
}  
}  
}

These are the steps i had used. But highlighting is not working on the last  
query.

On Wednesday, 27 August 2014 23:38:27 UTC+5:30, David Pilato wrote:

> I was talking about this:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-nested-type.html)
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 27 août 2014 à 19:08, sekharreddy mandapati \<[sekha...@gmail.com](mailto:sekha...@gmail.com)  
> \<javascript:\>\> a écrit :
> 
> An email contain multiple attachments. This number is not fixed. How can  
> we define nested documents if we our things are dynamic.
> 
> On Wednesday, 27 August 2014 22:17:23 UTC+5:30, sekharreddy mandapati  
> wrote:
> 
> > Thanks David,
> > 
> > I am using the following mapping. Can u please tell me the mapping for  
> > nested documents.
> > 
> > {  
> > "document":{  
> > "properties":{  
> > "attachmentContent":{  
> > "type":"attachment",  
> > "path":"full",  
> > "fields":{  
> > "attachmentContent":{  
> > "type":"string",  
> > "term\_vector":"with\_positions\_offsets",  
> > "store":true  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }
> > 
> > On Wednesday, 27 August 2014 22:08:29 UTC+5:30, David Pilato wrote:
> > 
> > > You can't add your own subfields to the attachment field.  
> > > Though this should be doable but requires some work IMO.
> > > 
> > > Also, I think you need to use nested documents. And add whatever field  
> > > you want in the nested doc (type, id...) and add the attachment field as  
> > > well.
> > > 
> > > HTH
> > > 
> > > --  
> > > David 😉  
> > > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > > 
> > > Le 27 août 2014 à 18:27, sekharreddy mandapati [sekha...@gmail.com](mailto:sekha...@gmail.com) a  
> > > écrit :
> > > 
> > > We have requirement of indexing email which have multiple attachments  
> > > and we have to highlight the search results. How can i map the highlight  
> > > string array to my multiple attachments.
> > > 
> > > My index mapping is
> > > 
> > > {  
> > > "document":{  
> > > "properties":{  
> > > "attachmentContent":{  
> > > "type":"attachment",  
> > > "path":"full",  
> > > "fields":{  
> > > "attachmentContent":{  
> > > "type":"string",  
> > > "term\_vector":"with\_positions\_offsets",  
> > > "store":true  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }
> > > 
> > > My indexed document is
> > > 
> > > {"userId":2,"attachmentContent":[{"content":"VGhpcyBpcyBudW1iZXIgb25lLg==","serviceAttachmentId":"1","fileName":"1.txt","type":"xml"},  
> > > {  
> > > {"content":"IkdvZCBTYXZlIHRoZSBRdWVlbiIgKGFsdGVybmF0aXZlbHkgIkdvZCBTYXZlIHRoZSBLaW5nIg==","serviceAttachmentId":"2","fileName":"2.txt","type":"excel"}]
> > > 
> > > }
> > > 
> > > My Questions are
> > > 
> > > 1.How can i access the "serviceAttachmentId" inside the  
> > > "attachmentContent" field which is of type attachment.  
> > > 2.How can i filter the documents based on type.
> > > 
> > > --  
> > > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/1c34c96f-c28f-4d4f-8c09-970160f9e669%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1c34c96f-c28f-4d4f-8c09-970160f9e669%40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/1c34c96f-c28f-4d4f-8c09-970160f9e669%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/1c34c96f-c28f-4d4f-8c09-970160f9e669%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > .  
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/bc509a84-aba2-47b6-a943-4221412be214%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/bc509a84-aba2-47b6-a943-4221412be214%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/bc509a84-aba2-47b6-a943-4221412be214%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/bc509a84-aba2-47b6-a943-4221412be214%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/7f538246-5e8a-4398-9742-3f329a9506d5%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/7f538246-5e8a-4398-9742-3f329a9506d5%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:05am UTC](https://discuss.elastic.co/t/how-can-we-index-array-of-attachments/19499/8 "2017-07-06T01:05:57Z")

</div>


