# How to work with Array fields and their mapping for efficient search and results

**URL:** <https://discuss.elastic.co/t/how-to-work-with-array-fields-and-their-mapping-for-efficient-search-and-results/253498>\
**Category:** Kibana\
**Created:** [October 27, 2020, 10:31pm UTC](https://discuss.elastic.co/t/how-to-work-with-array-fields-and-their-mapping-for-efficient-search-and-results/253498 "2020-10-27T22:31:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![katana\_handler](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/katana_handler/32/77965_2.png) [@katana\_handler](https://discuss.elastic.co/u/katana_handler)\
**Post date:** [October 27, 2020, 10:31pm UTC](https://discuss.elastic.co/t/how-to-work-with-array-fields-and-their-mapping-for-efficient-search-and-results/253498/1 "2020-10-27T22:31:42Z")

</div>

Hey community,  
This is my first post here seeking for knowledge. I was using the Dev Tools Console in kibana to learn querying. I came across this particular scenario where i couldn't get my head around.  
So I'll give an example here. My documents look like these:

```auto
{
...
names :['a', 'b', ..]
...
}

```

Now i have used the default mapping here. The names field has many names in it and using the console I want to list just the unique name across all docs and list them. Or see how many docs a particular unique name has occurred in, Or list all unique names have a certain prefix or suffix (tried using wildcard but that listed all documents and along with that all other names which did not match also showed up).  
Should i use a different mapping for these or is there something i missed. Please guide me here.  
I had looked for the documentation for a lot of things like aggregation, data range, analyze, cardinality etc etc.

Thanks a lot

---

<div class="post-metadata">

**Author:** ![wangqinghuan](https://avatars.discourse-cdn.com/v4/letter/w/d26b3c/32.png) [@wangqinghuan](https://discuss.elastic.co/u/wangqinghuan)\
**Post date:** [October 28, 2020, 2:15am UTC](https://discuss.elastic.co/t/how-to-work-with-array-fields-and-their-mapping-for-efficient-search-and-results/253498/2 "2020-10-28T02:15:49Z")

</div>

> [@katana\_handler](#):
>
> `.`

terms aggs could list unique name across all docs and its occus.

```
  {
        "aggs":{
            "names":{
                "terms":{
                    "field":"names.keyword"
                }
            }
        }
        
    }

```

---

<div class="post-metadata">

**Author:** ![katana\_handler](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/katana_handler/32/77965_2.png) [@katana\_handler](https://discuss.elastic.co/u/katana_handler)\
**Post date:** [October 28, 2020, 1:14pm UTC](https://discuss.elastic.co/t/how-to-work-with-array-fields-and-their-mapping-for-efficient-search-and-results/253498/3 "2020-10-28T13:14:14Z")

</div>

Hey..  
Yes I have tried this and it gives all the names and the count of the docs it appears in.  
But the problem is that it gives all the names. What if i want only those names starting with lets say "Will".. or maybe i don't want the list of names starting with will.. I want lets say number of names that starts with will. How do i do that..

Thanks a lot!!

---

<div class="post-metadata">

**Author:** ![wangqinghuan](https://avatars.discourse-cdn.com/v4/letter/w/d26b3c/32.png) [@wangqinghuan](https://discuss.elastic.co/u/wangqinghuan)\
**Post date:** [October 29, 2020, 3:36am UTC](https://discuss.elastic.co/t/how-to-work-with-array-fields-and-their-mapping-for-efficient-search-and-results/253498/4 "2020-10-29T03:36:51Z")

</div>

You must split your multiple-values field into multiple individual docs.

---

<div class="post-metadata">

**Author:** ![wangqinghuan](https://avatars.discourse-cdn.com/v4/letter/w/d26b3c/32.png) [@wangqinghuan](https://discuss.elastic.co/u/wangqinghuan)\
**Post date:** [October 29, 2020, 3:42am UTC](https://discuss.elastic.co/t/how-to-work-with-array-fields-and-their-mapping-for-efficient-search-and-results/253498/5 "2020-10-29T03:42:30Z")

</div>

{names:a,b,c,d} =\> {name:a},{name:b},{name:c}...

---

<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:** [November 26, 2020, 3:42am UTC](https://discuss.elastic.co/t/how-to-work-with-array-fields-and-their-mapping-for-efficient-search-and-results/253498/6 "2020-11-26T03:42:31Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
