# How to use search\_as\_you\_type datatype to get substring(infix) completion

**URL:** <https://discuss.elastic.co/t/how-to-use-search-as-you-type-datatype-to-get-substring-infix-completion/199570>\
**Category:** Elasticsearch\
**Created:** [September 16, 2019, 4:47am UTC](https://discuss.elastic.co/t/how-to-use-search-as-you-type-datatype-to-get-substring-infix-completion/199570 "2019-09-16T04:47:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MKU](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mku/32/48327_2.png) [@MKU](https://discuss.elastic.co/u/MKU)\
**Post date:** [September 16, 2019, 4:47am UTC](https://discuss.elastic.co/t/how-to-use-search-as-you-type-datatype-to-get-substring-infix-completion/199570/1 "2019-09-16T04:47:37Z")

</div>

Hi,  
The new search\_as\_you\_type feature should provide both infix and prefix completion, but i am seeing only prefix completion.

```auto
{
"mappings":{
"properties":{
"mail":{"type":"search_as_you_type"}
}}}

```

and the query which i am using is,

```auto
{
	"track_total_hits":true,
	"_source":"mail",
  "query": {
  "multi_match": {
      "query": "sam",
      "type": "bool_prefix",
      "fields": [
        "mail",
        "mail._2gram",
        "mail._3gram",
	"mail._index_prefix"
      ]
    }
  }
}

```

But in the response i am only able to see results which starts with sam like:  
[sam.a@gmail.com](mailto:sam.a@gmail.com)  
[sam.b@gmail.com](mailto:sam.b@gmail.com)

and i am also looking for results like :  
[aa.dgsfsamgh@gmail.com](mailto:aa.dgsfsamgh@gmail.com)

what changes should i make in query?

Thanks.....

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [September 16, 2019, 6:17am UTC](https://discuss.elastic.co/t/how-to-use-search-as-you-type-datatype-to-get-substring-infix-completion/199570/2 "2019-09-16T06:17:27Z")

</div>

What dues your mapping look like?

---

<div class="post-metadata">

**Author:** ![MKU](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mku/32/48327_2.png) [@MKU](https://discuss.elastic.co/u/MKU)\
**Post date:** [September 16, 2019, 6:22am UTC](https://discuss.elastic.co/t/how-to-use-search-as-you-type-datatype-to-get-substring-infix-completion/199570/3 "2019-09-16T06:22:29Z")

</div>

```auto
{
"mappings":{
	"dynamic":false,
"properties":{
"cn":{
	"type":"text",
	"fields":{
"keyword":{
"type":"keyword"
}
},
"analyzer":"autocomplete"
	},
"mail":{"type":"search_as_you_type"}
}
},
"settings":{
	"index.mapping.total_fields.limit":5000,
"index":{
"number_of_replicas":0
},
"analysis": {
      "analyzer": {
        "autocomplete": {
          "tokenizer": "my_tokenizer",
          "filter": [
            "lowercase"
          ]
        }
      },
      "tokenizer": {
        "my_tokenizer": {
          "type": "ngram",
          "min_gram": 3,
          "max_gram": 3,
          "token_chars": [
            "letter",
            "digit"
          ]
        }
      }
    }
}
}

```

basically i have more than 2K fields ,all have **text** data type only **cn** and **mail** have different ones. thats why i am mentioning only two.  
the custom analyzer is working fine for both infix and prefix completion but i want to use search\_as\_you\_type.

---

<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 14, 2019, 6:28am UTC](https://discuss.elastic.co/t/how-to-use-search-as-you-type-datatype-to-get-substring-infix-completion/199570/4 "2019-10-14T06:28:43Z")

</div>

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