Aggregation query returning single word results

Hello! Just wanted to preface that I am new to ElasticSearch so I apologize if I am missing any basic concepts.

I have an issue and I saw some other similar articles, but they were from quite awhile back and wanted to verify the issue I am seeing as well as its solutions.

I am working off an ElasticSearch index I did not create, and I am trying to get buckets of data for "categories" of items. In this case, its a person's name.

If I preform a query such as:

{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "category": "players"
          }
        },
        {
          "match": {
            "set_year": "2019"
          }
        },
        {
          "match": {
            "set_name": "pros"
          }
        }
      ]
    }
  }
}

I will get back a list, on this list under the "_source" section is a field called "player_name". When I do this query I will get back names such as "John Doe", "Bob the Builder", ect.. but I also get back all of the other attached data which will be a lot for client-side rendering.

So when learning about ElasticSearch this seemed like a good place to try aggregations. So I added the following query into the above query

   "size":0,
  "aggs": {
      "results": {
          "terms": {
              "field": "player_name",
              "size": 10000 //not sure how to get all, but someone suggested using a large number
          }
      }
  }

What happens when I do this, is that instead of getting "full" player names, they are returned as individual strings, such as: "John", "Doe", "Bob", "the", "Builder".

My question, is that it sounds like I need to make the field "player_name" have the property "index" be set to "not_analyzed". When I tried doing a PUT call to update the mappings it errored out on me and I am wondering if this requires me to make a brand new index, or if there are alternate ways to handle this with the index as-is right now? If I have to make a new index, is there an easy way to make the new index and then copy data from an existing index into it since all fields will still be named the same?

I also am unsure if setting "index" to "not_analyzed" will limit querying at all, in case someone searches for "Bob", I would still want to be able to locate "Bob the Builder" down the road.

Thank you!

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