# Search as you type field, best practice

**URL:** <https://discuss.elastic.co/t/search-as-you-type-field-best-practice/248289>\
**Category:** Elasticsearch\
**Created:** [September 11, 2020, 8:57am UTC](https://discuss.elastic.co/t/search-as-you-type-field-best-practice/248289 "2020-09-11T08:57:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniele\_Renda](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/daniele_renda/32/39939_2.png) [@Daniele\_Renda](https://discuss.elastic.co/u/Daniele_Renda)\
**Post date:** [September 11, 2020, 8:57am UTC](https://discuss.elastic.co/t/search-as-you-type-field-best-practice/248289/1 "2020-09-11T08:57:02Z")

</div>

Hi,  
I made some tests with search as you type field: [https://www.elastic.co/guide/en/elasticsearch/reference/7.x/search-as-you-type.html](https://www.elastic.co/guide/en/elasticsearch/reference/7.x/search-as-you-type.html)

I've an index containing products. Each product(document) have many fields like: lineDescription, model, colorDescription and so on.  
On those fields in some part of my application I have some autocomplete that help the user during typing: for example on model field, lineDescription, and so on.

I saw how to create a field of "search\_as\_you\_type" type, but I don't know if I should convert my original fields (they were text) into this type or if it's better to add a new field "search\_as\_you\_type" in addition to the original field with the same data inside.

In short, should I have this:

```
 "lineDescription": {
                "type": "text",
                "fields": {
                  "ngram": {
                    "type": "text",
                    "analyzer": "ngram",
                    "search_analyzer": "standard"
                  },
                  "keyword": {
                    "type": "keyword"
                  }
                }
              },
			  "lineDescription_as_you_type": {
                "type": "search_as_you_type"              
              },

```

just this:

```
  "lineDescription_as_you_type": {
                    "type": "search_as_you_type"              
                  },

```

or

```
 "lineDescription": {
                    "type": "text",
                    "fields": {
                      "ngram": {
                        "type": "text",
                        "analyzer": "ngram",
                        "search_analyzer": "standard"
                      },
                      "keyword": {
                        "type": "keyword"
                      },
                      "suggest": {
                          "type": "search_as_you_type"              
                      },
                    }
                  },

```

I was asking myse which is the most long term solution to avoid to wake up a day and say "oh, I can't use this query on lineDescription field because it has search\_as\_you\_type type". For example I also want to do exact matching on lineDescription field as well, and for that reason I created also .keyword variant of the field.

I'm sure you guys can suggest me a more wide vision about modeling this specific use case.

Thanks

---

<div class="post-metadata">

**Author:** ![Peter\_Steenbergen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/peter_steenbergen/32/22888_2.png) [@Peter\_Steenbergen](https://discuss.elastic.co/u/Peter_Steenbergen)\
**Post date:** [September 11, 2020, 2:03pm UTC](https://discuss.elastic.co/t/search-as-you-type-field-best-practice/248289/2 "2020-09-11T14:03:34Z")

</div>

Hmm, what I did for a similar use-case was creating a new field called: product\_search\_as\_you\_type of the type: search\_as\_you\_type.

And then for lineDescription, i would use copy\_to: with the value: product\_search\_as\_you\_type.  
In this case all the lines of the product will be copied to that field and you can search all the contents of the object without worrying about not using that field later in a different kind of way.

---

<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 9, 2020, 2:03pm UTC](https://discuss.elastic.co/t/search-as-you-type-field-best-practice/248289/3 "2020-10-09T14:03:46Z")

</div>

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