# Adding keyword field to existing index text field for term agg / word autocomplete

**URL:** https://discuss.elastic.co/t/adding-keyword-field-to-existing-index-text-field-for-term-agg-word-autocomplete/164475
**Category:** Elasticsearch
**Created:** [January 16, 2019, 1:27pm UTC](https://discuss.elastic.co/t/adding-keyword-field-to-existing-index-text-field-for-term-agg-word-autocomplete/164475 "2019-01-16T13:27:08Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![justinmoser](https://avatars.discourse-cdn.com/v4/letter/j/ec9cab/32.png) [@justinmoser](https://discuss.elastic.co/u/justinmoser)
#### Post date: [January 16, 2019, 1:27pm UTC](https://discuss.elastic.co/t/adding-keyword-field-to-existing-index-text-field-for-term-agg-word-autocomplete/164475/1 "2019-01-16T13:27:08Z")

</div>

Hi,  
I want to be able to search two text fields on both full text search and keyword based for aggregation so that I can implement single word autocomplete, similar to the discussion here:

> [@Autocomplete of single words](https://discuss.elastic.co/t/autocomplete-of-single-words/31326):
>
> Hi, everyone, following problem: I want to have an autocompletion of single words. This means: if I type in "bor", I want to get "boring (num: 29)" and "border (num: 10)" back. "border" and "boring" are parts of several large texts. I do not want to get the whole text, just the number of documents there "boring" and "border" occurs and - of course - the terms "boring" and "border". I think I have to use [https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-completio…](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-completion.html)

However when i created the index i set the fields i want to search to text fields (without the keyword field).

So i updated the mapping for these two fields as suggested in this link:

> **[fielddata mapping parameter | Elasticsearch Guide \[8.11\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/fielddata.html)**

In my case I updated the abstract and the title properties.

The index currently was populated with 1.6 million documents, and this was done before i updated the mapping. After the update, my mapping is as follows:

```
{
  "library": {
    "mappings": {
      "paper": {
        "properties": {
          "abstract": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword"
              }
            }
          },
          "added_date": {
            "type": "integer"
          },
          "author_strings_json": {
            "type": "keyword"
          },
          "authors_json": {
            "properties": {
              "id": {
                "type": "long"
              },
              "name": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              }
            }
          },
          "created_at": {
            "type": "integer"
          },
          "doi": {
            "type": "keyword"
          },
          "id": {
            "type": "long"
          },
          "image_url": {
            "type": "keyword"
          },
          "journal_id": {
            "type": "integer"
          },
          "mendeley_id": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "pdf_url": {
            "type": "keyword"
          },
          "processed": {
            "type": "boolean"
          },
          "published_date": {
            "type": "integer"
          },
          "s3_image_name": {
            "type": "keyword"
          },
          "suggest": {
            "type": "completion",
            "analyzer": "simple",
            "preserve_separators": true,
            "preserve_position_increments": true,
            "max_input_length": 50
          },
          "title": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword"
              }
            }
          },
          "unpaywall_urls": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "updated_at": {
            "type": "long"
          },
          "url": {
            "type": "keyword"
          },
          "valid": {
            "type": "boolean"
          }
        }
      }
    }
  }
}

```

However, when I use the following query:

```
GET library/_search?pretty
{
  "query": {
    "match_phrase_prefix": {
      "title.keyword": "arti"
    }
  },
  "size": 1, 
  "aggs": {
    "myagg": {
      "terms": {
        "field": "title.keyword",
        "include": "arti.*", 
        "size": 1
      }
    }
  }
}

```

I get no results (the buckets field is empty in the result)

Any idea what im doing wrong?

Thanks!  
Justin

---

<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: [February 13, 2019, 1:27pm UTC](https://discuss.elastic.co/t/adding-keyword-field-to-existing-index-text-field-for-term-agg-word-autocomplete/164475/2 "2019-02-13T13:27:14Z")

</div>

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