Search_as_you_type field as subfield

Hello experts,
I'm using ES v7. I noticed there's a fantastic type called 'search_ar_you_type' can help me with auto-completion. The samples from doc is map the field to this type like:

{
  "mappings": {
    "properties": {
      "my_field": {
        "type": "search_as_you_type"
      }
    }
  }
}

As I don't want to change my current index mapping, the property type is "text", can I add a subfield with 'search_as_you_type' type? like this

{
  "mappings": {
    "properties": {
      "my_field": {
        "type": "text",
        "fields": {
          "sayt": {
            "type": "search_as_you_type"
          }
        }
      }
    }
  }
}

I ask this because I know 'search_as_you_type' itself also add subfields like '_2gram' and etc, which are like subfield of subfield, and I'm not sure this works well or not.
Thanks

yes, you just append the fieldnames, using dots.. like my_field.sayt._2gram. Note that there was an issue if you define the main field to be search as you type containing other multi fields, that has only been sovled in 8.1, see Search as you type field to support subfields by javanna · Pull Request #82430 · elastic/elasticsearch · GitHub

1 Like

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