# Can I make string field as aggregatable?

**URL:** <https://discuss.elastic.co/t/can-i-make-string-field-as-aggregatable/101881>\
**Category:** Kibana\
**Created:** [September 26, 2017, 4:10pm UTC](https://discuss.elastic.co/t/can-i-make-string-field-as-aggregatable/101881 "2017-09-26T16:10:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ctayal1211](https://avatars.discourse-cdn.com/v4/letter/c/e95f7d/32.png) [@ctayal1211](https://discuss.elastic.co/u/ctayal1211)\
**Post date:** [September 26, 2017, 4:10pm UTC](https://discuss.elastic.co/t/can-i-make-string-field-as-aggregatable/101881/1 "2017-09-26T16:10:17Z")

</div>

Hi,

I want to make string field as aggregatable.

 ![20 AM](https://us1.discourse-cdn.com/elastic/original/3X/b/4/b41c05da278ac6f406ae9884e81989e5fb5da324.png)

I have visualization json as follows:

{  
"\_id": "Top-Switches-by-Endpoint-Count",  
"\_type": "visualization",  
"\_source": {  
"description": "",  
"uiStateJSON": "{}",  
"title": "Top Switches by Endpoint Count",  
"version": 1,  
"kibanaSavedObjectMeta": {  
"searchSourceJSON": "{ "index": "epl\_cache\_today", "query": { "query\_string": { "query": "\*", "analyze\_wildcard": true } }, "filter": }"  
},  
"visState": "{ "title": "Current View: Top ToRs for Fabric", "type": "pie", "params": { "shareYAxis": true, "addTooltip": true, "addLegend": true, "isDonut": true }, "aggs": [{ "id": "1", "type": "count", "schema": "metric", "params": {} }, { "id": "2", "type": "terms", "schema": "segment", "params": { "field": "Switch\_Name", "size": 5, "order": "desc", "orderBy": "1" } }], "listeners": {}}"  
}  
}

But when I import this json as visualization in kibana 5.5.3 I see an error:

Saved "field" parameter is now invalid. Please select a new field.  
Visualize: "field" is a required parameter

I have mapping as following example

{  
"name": "Switch\_Name",  
"type": "text",  
"fields": {  
"keyword": {  
"type": "keyword"  
}  
},  
"count": 0,  
"scripted": false,  
"indexed": true,  
"analyzed": false,  
"doc\_values": true  
}

and visualization schema as follows:

"visualization" : {  
"properties" : {  
"description" : {  
"type" : "text"  
},  
"kibanaSavedObjectMeta" : {  
"properties" : {  
"searchSourceJSON" : {  
"type" : "text"  
}  
}  
},  
"savedSearchId" : {  
"type" : "text"  
},  
"title" : {  
"type" : "text"  
},  
"uiStateJSON" : {  
"type" : "text"  
},  
"version" : {  
"type" : "integer"  
},  
"visState" : {  
"type" : "text"  
}  
}  
}

When I select split slices, in aggregation when I select terms I do not see any string fields in it

Can anyone please help me with this?

Thanks,  
Chirag

---

<div class="post-metadata">

**Author:** ![vijay.sangha](https://avatars.discourse-cdn.com/v4/letter/v/4491bb/32.png) [@vijay.sangha](https://discuss.elastic.co/u/vijay.sangha)\
**Post date:** [September 26, 2017, 4:44pm UTC](https://discuss.elastic.co/t/can-i-make-string-field-as-aggregatable/101881/2 "2017-09-26T16:44:39Z")

</div>

You will need to update the field mapping in ES to keyword.

It will not take effect on existing data and you might have to re-index the data.

New data flowing in will be able indexed as per the new field mapping.

PUT /my\_index\_name/\_mapping/my\_type\_name  
{  
"my\_type\_name": {  
"properties": {  
"tag": {  
"type": "keyword"  
}  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![ctayal1211](https://avatars.discourse-cdn.com/v4/letter/c/e95f7d/32.png) [@ctayal1211](https://discuss.elastic.co/u/ctayal1211)\
**Post date:** [September 26, 2017, 6:16pm UTC](https://discuss.elastic.co/t/can-i-make-string-field-as-aggregatable/101881/3 "2017-09-26T18:16:54Z")

</div>

@vijay.sangha

I did following but getting error:

PUT epl\_cache\_today/\_mapping/endpoint  
{  
"endpoint": {  
"properties": {  
"Br\_Domain": {  
"type": "keyword"  
}  
}  
}  
}

Result:  
{  
"error": {  
"root\_cause": [  
{  
"type": "illegal\_argument\_exception",  
"reason": "mapper [Br\_Domain] of different type, current\_type [text], merged\_type [keyword]"  
}  
],  
"type": "illegal\_argument\_exception",  
"reason": "mapper [Br\_Domain] of different type, current\_type [text], merged\_type [keyword]"  
},  
"status": 400  
}

---

<div class="post-metadata">

**Author:** ![ctayal1211](https://avatars.discourse-cdn.com/v4/letter/c/e95f7d/32.png) [@ctayal1211](https://discuss.elastic.co/u/ctayal1211)\
**Post date:** [September 26, 2017, 6:19pm UTC](https://discuss.elastic.co/t/can-i-make-string-field-as-aggregatable/101881/4 "2017-09-26T18:19:37Z")

</div>

> <https://stackoverflow.com/questions/42925217/migrate-field-type-from-text-to-keyword-on-elasticsearchedit>

OK finally i see in the doc that it's not possible to change data type of a field :

Updating existing mappings

Other than where documented, existing type and field mappings cannot be updated. Changing the mapping would mean invalidating already indexed documents. Instead, you should create a new index with the correct mappings and reindex your data into that index.  
So the only solution is to :

Recreate a new index with good data types  
Reindex the data with the Reindex API

---

<div class="post-metadata">

**Author:** ![ctayal1211](https://avatars.discourse-cdn.com/v4/letter/c/e95f7d/32.png) [@ctayal1211](https://discuss.elastic.co/u/ctayal1211)\
**Post date:** [September 26, 2017, 6:41pm UTC](https://discuss.elastic.co/t/can-i-make-string-field-as-aggregatable/101881/5 "2017-09-26T18:41:40Z")

</div>

It is not working

I rebuilt the complete schema as follows

```
{
    "name": "VRF",
    "type": "keyword",
    "count": 0,
    "scripted": false,
    "indexed": true,
    "analyzed": false,
    "doc_values": true
},

```

still it shows following:  
{  
"epl\_cache\_today": {  
"mappings": {  
"endpoint": {  
"properties": {  
"VRF": {  
"type": "text"  
}  
}  
}  
}  
}  
}

---

<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:** [October 24, 2017, 6:42pm UTC](https://discuss.elastic.co/t/can-i-make-string-field-as-aggregatable/101881/6 "2017-10-24T18:42:02Z")

</div>

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