# Finding the search as you type match for multi value fields

**URL:** <https://discuss.elastic.co/t/finding-the-search-as-you-type-match-for-multi-value-fields/375806>\
**Category:** Elasticsearch\
**Created:** [March 12, 2025, 8:09pm UTC](https://discuss.elastic.co/t/finding-the-search-as-you-type-match-for-multi-value-fields/375806 "2025-03-12T20:09:09Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![elasticfan1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elasticfan1/32/122903_2.png) [@elasticfan1](https://discuss.elastic.co/u/elasticfan1)\
**Post date:** [March 12, 2025, 8:09pm UTC](https://discuss.elastic.co/t/finding-the-search-as-you-type-match-for-multi-value-fields/375806/1 "2025-03-12T20:09:09Z")

</div>

I have a multi value field called tags. Let's say my doc has the following values for the tags field:

["test trim", "yellow boat", "nice car"]

If I query for "boa", I want to get back "yellow boat". However result returns all of the fields.

I am trying to use this feature for auto complete. I tried the completion suggester, but it only works with prefixes. I want it to work with infix as well.

---

<div class="post-metadata">

**Author:** ![jessgarson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jessgarson/32/129841_2.png) [@jessgarson](https://discuss.elastic.co/u/jessgarson)\
**Post date:** [March 13, 2025, 2:53pm UTC](https://discuss.elastic.co/t/finding-the-search-as-you-type-match-for-multi-value-fields/375806/2 "2025-03-13T14:53:52Z")

</div>

Thanks for reaching out, @elasticfan1. Have you thought about using [N-gram tokenizer](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-ngram-tokenizer.html) or [highlighting](https://www.elastic.co/guide/en/elasticsearch/reference/current/highlighting.html)?

---

<div class="post-metadata">

**Author:** ![elasticfan1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elasticfan1/32/122903_2.png) [@elasticfan1](https://discuss.elastic.co/u/elasticfan1)\
**Post date:** [March 13, 2025, 4:48pm UTC](https://discuss.elastic.co/t/finding-the-search-as-you-type-match-for-multi-value-fields/375806/3 "2025-03-13T16:48:50Z")

</div>

Yeah I've used the search\_as\_you\_type. While it matches the record correctly, it doesn't tell me which field it matched it. Also it will return duplicates.

My use case is an autocomplete for titles and tags. It needs to return a fixed number of matches with infix matches.

Search as you type will match on the records, but it will return a list of records instead of a list of field values it matched on. This causes dupes and issues when the field value has multiple values.

Are you saying I should use highlighting to find the exact multivalue field it matched on? Is there a more elegant way?

---

<div class="post-metadata">

**Author:** ![jessgarson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jessgarson/32/129841_2.png) [@jessgarson](https://discuss.elastic.co/u/jessgarson)\
**Post date:** [March 13, 2025, 5:47pm UTC](https://discuss.elastic.co/t/finding-the-search-as-you-type-match-for-multi-value-fields/375806/4 "2025-03-13T17:47:34Z")

</div>

Thanks for following up, @elasticfan1.

You're right about the limitations of `search_as_you_type` when working with multi-value fields. The highlighting approach is one way to identify which specific field values matched, but there are more elegant solutions.

Would setting up an index with [edge n-grams](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-edgengram-tokenizer.html) work for you?

---

<div class="post-metadata">

**Author:** ![elasticfan1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elasticfan1/32/122903_2.png) [@elasticfan1](https://discuss.elastic.co/u/elasticfan1)\
**Post date:** [March 14, 2025, 3:44pm UTC](https://discuss.elastic.co/t/finding-the-search-as-you-type-match-for-multi-value-fields/375806/5 "2025-03-14T15:44:20Z")

</div>

Wouldn't I get the same issue with the edge n-grams? I thought search\_as\_you\_type just creates those ngram fields for you automatically?

Are you saying I can use a different analyzer with the completion suggester? If so, what should the settings be?

Record 1 :  
{  
title : hello there  
tags : ['yellow boat', 'blue hair']  
}

Record 2 :  
{  
title : hello there  
tags : ['hot peppers', 'green frog']  
}

---

<div class="post-metadata">

**Author:** ![jessgarson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jessgarson/32/129841_2.png) [@jessgarson](https://discuss.elastic.co/u/jessgarson)\
**Post date:** [March 14, 2025, 6:07pm UTC](https://discuss.elastic.co/t/finding-the-search-as-you-type-match-for-multi-value-fields/375806/6 "2025-03-14T18:07:33Z")

</div>

Thanks, @elasticfan1. I was thinking of creating an index similar to this:

```auto
PUT /autocomplete_index
{
  "settings": {
    "analysis": {
      "tokenizer": {
        "ngram_tokenizer": {
          "type": "ngram",
          "min_gram": 2,
          "max_gram": 20,
          "token_chars": ["letter", "digit", "whitespace"]
        }
      },
      "analyzer": {
        "custom_ngram": {
          "type": "custom",
          "tokenizer": "ngram_tokenizer",
          "filter": ["lowercase"]
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "title": {
        "type": "text"
      },
      "tags": {
        "type": "text",
        "analyzer": "custom_ngram",   
        "search_analyzer": "standard"
      }
    }
  }
}

```

Let me know if something like this would work for your needs.

---

<div class="post-metadata">

**Author:** ![elasticfan1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elasticfan1/32/122903_2.png) [@elasticfan1](https://discuss.elastic.co/u/elasticfan1)\
**Post date:** [March 17, 2025, 1:54am UTC](https://discuss.elastic.co/t/finding-the-search-as-you-type-match-for-multi-value-fields/375806/7 "2025-03-17T01:54:20Z")

</div>

Is this index setting the same as using a search-as-you-type property type?

---

<div class="post-metadata">

**Author:** ![jessgarson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jessgarson/32/129841_2.png) [@jessgarson](https://discuss.elastic.co/u/jessgarson)\
**Post date:** [March 20, 2025, 12:26am UTC](https://discuss.elastic.co/t/finding-the-search-as-you-type-match-for-multi-value-fields/375806/8 "2025-03-20T00:26:04Z")

</div>

Sorry for the delay, @elasticfan1. I was traveling for work the past few days and just returned today. I don't believe it's the same, but I'm interested in seeing how your index is currently set up.
