# Get the specific values from arrays elasticsearch

**URL:** https://discuss.elastic.co/t/get-the-specific-values-from-arrays-elasticsearch/194358
**Category:** Elasticsearch
**Created:** [August 8, 2019, 6:18am UTC](https://discuss.elastic.co/t/get-the-specific-values-from-arrays-elasticsearch/194358 "2019-08-08T06:18:53Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![elasticpatrick](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elasticpatrick/32/49939_2.png) [@elasticpatrick](https://discuss.elastic.co/u/elasticpatrick)
#### Post date: [August 8, 2019, 6:18am UTC](https://discuss.elastic.co/t/get-the-specific-values-from-arrays-elasticsearch/194358/1 "2019-08-08T06:18:53Z")

</div>

Hi, I have a field "user\_names" having list of users names in my "user" index. I want to query through the user\_names field and get only match values from the array and if possible can I get apply aggregation on the user\_names field.  
My mapping is :

```auto
"mappings": {
      "properties": {
        "user_names": {
          "type": "text",
          "analyzer": "autocomplete",
          "search_analyzer": "autocomplete_search"
        }
      }
    }

```

And the index is as follow:

```auto
[
      {
        "_index": "users",
        "_type": "_doc",
        "_id": "1",
        "_score": 1.0,
        "_source": {
          "user_names": [
            "pratik",
            "sundar pichai",
            "bill gates",
            "elon mask"
          ]
        }
      },
     {
        "_index": "user",
        "_type": "_doc",
        "_id": "2",
        "_score": 1.0,
        "_source": {
          "user_names": [
            "prob",
            "shrey",
            "eminem"
          ]
        }
      }
    ]

```

The query which i wrote is

```auto
GET user/_search
{
  "query": {
    "bool": {
      "must": [
       {"match": {
         "user_names": "pr"
       }}
      ]
    }
  }
}

```

I only want get the "pratik" and "prob" from the above documents.

---

<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: [September 5, 2019, 6:19am UTC](https://discuss.elastic.co/t/get-the-specific-values-from-arrays-elasticsearch/194358/2 "2019-09-05T06:19:01Z")

</div>

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