Get the specific values from arrays elasticsearch

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 :

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

And the index is as follow:

[
      {
        "_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

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

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

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