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

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:

{
...
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

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

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

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!!

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

1 Like

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

1 Like

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