# How to create custom categories for text files indexed in Elasticsearch using the attachment plugin?

**URL:** <https://discuss.elastic.co/t/how-to-create-custom-categories-for-text-files-indexed-in-elasticsearch-using-the-attachment-plugin/15739>\
**Category:** Elasticsearch\
**Created:** [February 11, 2014, 7:37pm UTC](https://discuss.elastic.co/t/how-to-create-custom-categories-for-text-files-indexed-in-elasticsearch-using-the-attachment-plugin/15739 "2014-02-11T19:37:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sagar\_Singh](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@Sagar\_Singh](https://discuss.elastic.co/u/Sagar_Singh)\
**Post date:** [February 11, 2014, 7:37pm UTC](https://discuss.elastic.co/t/how-to-create-custom-categories-for-text-files-indexed-in-elasticsearch-using-the-attachment-plugin/15739/1 "2014-02-11T19:37:03Z")

</div>

I have my mappings as such

```
{
"attachment": {
    "properties": {
        "file": {
            "type": "attachment",
            "fields": {
                "title": {
                    "store": "yes"
                },
                "author": {
                    "store": "yes"
                },
                "date": {
                    "store": "yes"
                },
                "keywords": {
                    "store": "yes"
                },
                "content_type": {
                    "store": "yes"
                },
                "file": {
                    "term_vector": "with_positions_offsets",
                    "store": "yes",
                    "index": "analyzed"
                    }
               }
            }
        }
    }
}

```

I want to be able to add custom categories to each file, for example if the  
file is an html file then i want to read the meta tag inside and add those  
categories.

If there is a better approach please let me know so as well, I am just  
trying to get my feet wet with Elasticsearch and just working with the  
attachment plugin for the first time.

also created a SO question on  
it: [http://stackoverflow.com/questions/21711216/how-to-create-custom-categories-for-text-files-indexed-in-elasticsearch-using-th](http://stackoverflow.com/questions/21711216/how-to-create-custom-categories-for-text-files-indexed-in-elasticsearch-using-th)

--  
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/a7ce1436-bb86-40d2-a5ec-82a4d7fada75%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a7ce1436-bb86-40d2-a5ec-82a4d7fada75%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:** ![Binh\_Ly](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@Binh\_Ly](https://discuss.elastic.co/u/Binh_Ly)\
**Post date:** [February 11, 2014, 8:57pm UTC](https://discuss.elastic.co/t/how-to-create-custom-categories-for-text-files-indexed-in-elasticsearch-using-the-attachment-plugin/15739/2 "2014-02-11T20:57:52Z")

</div>

You can simply add more fields on the same level as file. For example:

"mappings": {  
"doc": {  
"properties" : {  
"file" : {  
"type" : "attachment",  
"fields": {  
"file": { "store": "yes" }  
}  
},  
"meta1": {  
"type": "string",  
"store": "yes"  
}  
}  
}  
}

And then when you index, just specify a value for the "meta1" field in  
addition to your "file" field.

--  
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/d53e93b6-c595-43a8-8829-a2f3b68014d1%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d53e93b6-c595-43a8-8829-a2f3b68014d1%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:** ![Binh\_Ly](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@Binh\_Ly](https://discuss.elastic.co/u/Binh_Ly)\
**Post date:** [February 11, 2014, 9:00pm UTC](https://discuss.elastic.co/t/how-to-create-custom-categories-for-text-files-indexed-in-elasticsearch-using-the-attachment-plugin/15739/3 "2014-02-11T21:00:02Z")

</div>

Ooops, forgot to mention "store": "yes" is optional. You don't have to  
store anything if you don't need stored metadata fields.

On Tuesday, February 11, 2014 3:57:52 PM UTC-5, Binh Ly wrote:

> You can simply add more fields on the same level as file. For example:
> 
> "mappings": {  
> "doc": {  
> "properties" : {  
> "file" : {  
> "type" : "attachment",  
> "fields": {  
> "file": { "store": "yes" }  
> }  
> },  
> "meta1": {  
> "type": "string",  
> "store": "yes"  
> }  
> }  
> }  
> }
> 
> And then when you index, just specify a value for the "meta1" field in  
> addition to your "file" field.

--  
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/e6729c4d-14c6-4dbd-bd0a-8d96c3c97019%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e6729c4d-14c6-4dbd-bd0a-8d96c3c97019%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:** ![Sagar\_Singh](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@Sagar\_Singh](https://discuss.elastic.co/u/Sagar_Singh)\
**Post date:** [February 11, 2014, 9:19pm UTC](https://discuss.elastic.co/t/how-to-create-custom-categories-for-text-files-indexed-in-elasticsearch-using-the-attachment-plugin/15739/4 "2014-02-11T21:19:51Z")

</div>

Thanks, I guess i should be asking how would i set those meta data during  
indexing, is there a feature that ES can perform for me. i saw a way to  
have custom analyzers and was trying those out to see if i can use that to  
set the meta for me if there is something in that document.

On Tuesday, February 11, 2014 4:00:02 PM UTC-5, Binh Ly wrote:

> Ooops, forgot to mention "store": "yes" is optional. You don't have to  
> store anything if you don't need stored metadata fields.
> 
> On Tuesday, February 11, 2014 3:57:52 PM UTC-5, Binh Ly wrote:
> 
> > You can simply add more fields on the same level as file. For example:
> > 
> > "mappings": {  
> > "doc": {  
> > "properties" : {  
> > "file" : {  
> > "type" : "attachment",  
> > "fields": {  
> > "file": { "store": "yes" }  
> > }  
> > },  
> > "meta1": {  
> > "type": "string",  
> > "store": "yes"  
> > }  
> > }  
> > }  
> > }
> > 
> > And then when you index, just specify a value for the "meta1" field in  
> > addition to your "file" field.

--  
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/38c360c3-b0e1-4da9-9018-ee951358386e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/38c360c3-b0e1-4da9-9018-ee951358386e%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:50am UTC](https://discuss.elastic.co/t/how-to-create-custom-categories-for-text-files-indexed-in-elasticsearch-using-the-attachment-plugin/15739/5 "2017-07-06T01:50:55Z")

</div>


