# Need help with how to name fields when doing a search\_as\_you\_type query

**URL:** <https://forum.opensearch.org/t/need-help-with-how-to-name-fields-when-doing-a-search-as-you-type-query/18011>\
**Category:** OpenSearch\
**Created:** [February 22, 2024, 3:33am UTC](https://forum.opensearch.org/t/need-help-with-how-to-name-fields-when-doing-a-search-as-you-type-query/18011 "2024-02-22T03:33:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![JamesMatson](https://avatars.discourse-cdn.com/v4/letter/j/7ea924/32.png) [@JamesMatson](https://forum.opensearch.org/u/JamesMatson)\
**Post date:** [February 22, 2024, 3:33am UTC](https://forum.opensearch.org/t/need-help-with-how-to-name-fields-when-doing-a-search-as-you-type-query/18011/1 "2024-02-22T03:33:43Z")

</div>

**Versions** (relevant - OpenSearch/Dashboard/Server OS/Browser):

Opensearch serverless (AWS)

**Describe the issue** :

We have a requirement to allow our clients website to start typing into a search box letter by letter and filter results coming back quickly. For example, customer name.  
We might have John and James. The client presses J and records for both come back, then they press a (so Ja) and now it filters only to the ‘James’ records.

My understanding is with a lot of data, this needs to be quite performant, so we have indexed the fields that need this kind of search as you type ability as search\_as\_you\_type fields in  
addition to text (as they can be matched exactly, as well).

```
    "customerName": {
      "type": "text",
      "fields": {
        "keyword": {
          "type": "keyword"
        },
        "suggestion": {
          "type": "search_as_you_type",
          "doc_values": false,
          "max_shingle_size": 3
        }
      }
    },

```

When querying these fields, we are just specifying the field as customerNumber.suggestion (for example):

```
          },
          {
            "multi_match": {
              "fields": [
                "customerNumber.suggestion",
                "orderReference.suggestion"
              ],
              "query": "string",
              "type": "phrase_prefix"
            }
          }
        ]

```

But in OpenSearch documentation like [Search as you type - OpenSearch Documentation](https://opensearch.org/docs/latest/field-types/supported-field-types/search-as-you-type/) the examples show queries with these fields like \_2gram, or \_3gram? Do we need to actually specifiy these when searching?

GET books/\_search  
{  
“query”: {  
“multi\_match”: {  
“query”: “tw one”,  
“type”: “bool\_prefix”,  
“fields”: [  
“suggestions”,  
“suggestions.\_2gram”,  
“suggestions.\_3gram”  
]  
}  
}  
}

We have tried both ways and it doesn’t seem to make any difference. So do we need to specify these \_3gram field ‘names’? Or no?

---

<div class="post-metadata">

**Author:** ![radu.gheorghe](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.opensearch.org/radu.gheorghe/32/3516_2.png) [@radu.gheorghe](https://forum.opensearch.org/u/radu.gheorghe)\
**Post date:** [March 1, 2024, 1:37pm UTC](https://forum.opensearch.org/t/need-help-with-how-to-name-fields-when-doing-a-search-as-you-type-query/18011/2 "2024-03-01T13:37:22Z")

</div>

Yes, you’ll want to point the query to all the sub-fields in order to get more accurate matches (e.g. more words in the corect order) ranked higher.
