# Mapping for lists and searching within them?

**URL:** https://discuss.elastic.co/t/mapping-for-lists-and-searching-within-them/7692
**Category:** Elasticsearch
**Created:** [May 14, 2012, 9:38pm UTC](https://discuss.elastic.co/t/mapping-for-lists-and-searching-within-them/7692 "2012-05-14T21:38:59Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![T\_Vinod\_Gupta](https://avatars.discourse-cdn.com/v4/letter/t/fbc32d/32.png) [@T\_Vinod\_Gupta](https://discuss.elastic.co/u/T_Vinod_Gupta)
#### Post date: [May 14, 2012, 9:38pm UTC](https://discuss.elastic.co/t/mapping-for-lists-and-searching-within-them/7692/1 "2012-05-14T21:38:59Z")

</div>

Hi,  
I have an index in ES where one of the fields (say "tags") in the document  
is actually a list. The way I index is roughly as below -

```
            List<String> customActionList = new ArrayList<String>();

            customActionList.add("tag1");
            customActionList.add("tag2");
            XContentBuilder xcb = jsonBuilder().startObject();
            xcb = xcb.field("tag", customActionList);
            xcb = xcb.endObject();
            IndexResponse indexResponse =

```

irb.setSource(xcb).execute().actionGet();

but in the mapping, i dont see it as a list. it shows as a string. is that  
fine?

curl -XGET '[http://localhost:9200/](http://localhost:9200/)//\_mapping'  
{:{"properties":{..."tags":{"type":"string"}...}

Assuming this is correct, how do i search for all documents which have a  
tag, say "my\_tag" in its "tags" list? I am not able to find the  
documentation for this kind of search.

thanks

---

<div class="post-metadata">

### Author: ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)
#### Post date: [May 15, 2012, 1:00pm UTC](https://discuss.elastic.co/t/mapping-for-lists-and-searching-within-them/7692/2 "2012-05-15T13:00:29Z")

</div>

Yes, this is fine. You can search it the same way you search for fields  
with a single value. To find all documents which have a tag "my\_tag", just  
search for tags:mytag.

It might be also useful to make this field not\_analyzed to avoid issues  
with tags that contain spaces and special characters.

On Monday, May 14, 2012 5:38:59 PM UTC-4, T Vinod Gupta wrote:

> Hi,  
> I have an index in ES where one of the fields (say "tags") in the document  
> is actually a list. The way I index is roughly as below -
> 
> ```
> List<String> customActionList = new ArrayList<String>();   
>          
> customActionList.add("tag1");
> customActionList.add("tag2");
> XContentBuilder xcb = jsonBuilder().startObject();
> xcb = xcb.field("tag", customActionList);
> xcb = xcb.endObject();
> IndexResponse indexResponse = 
> 
> ```
> 
> irb.setSource(xcb).execute().actionGet();
> 
> but in the mapping, i dont see it as a list. it shows as a string. is that  
> fine?
> 
> curl -XGET '[http://localhost:9200/](http://localhost:9200/)//\_mapping'  
> {:{"properties":{..."tags":{"type":"string"}...}
> 
> Assuming this is correct, how do i search for all documents which have a  
> tag, say "my\_tag" in its "tags" list? I am not able to find the  
> documentation for this kind of search.
> 
> thanks

---

<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:28am UTC](https://discuss.elastic.co/t/mapping-for-lists-and-searching-within-them/7692/3 "2017-07-06T03:28:50Z")

</div>


