# Search as you type with 100k rows, help scoring

**URL:** <https://discuss.elastic.co/t/search-as-you-type-with-100k-rows-help-scoring/312412>\
**Category:** Elasticsearch\
**Created:** [August 18, 2022, 9:42pm UTC](https://discuss.elastic.co/t/search-as-you-type-with-100k-rows-help-scoring/312412 "2022-08-18T21:42:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![samtwilliams](https://avatars.discourse-cdn.com/v4/letter/s/f07891/32.png) [@samtwilliams](https://discuss.elastic.co/u/samtwilliams)\
**Post date:** [August 18, 2022, 9:42pm UTC](https://discuss.elastic.co/t/search-as-you-type-with-100k-rows-help-scoring/312412/1 "2022-08-18T21:42:05Z")

</div>

Hi All,

I have an index that contains drug names (100k of them),I'm using a react front end to search as you type which is working quite well except the scoring coming back is not what I expect despite endless fiddling.

The following are returned when searching for "omep" with the same score;

- Esomeprazole 20mg gastro-resistant granules sachets (Alliance Healthcare (Distribution) Ltd) 28 sachet
- Omeprazole 20mg gastro-resistant tablets 7 tablet

(there are actually lots of results with the same score, i've just used these two to demonstrate with ease)

I'm hoping that the second line can be scored higher than the first line. I'm designing the search so the user can type anything (like google) so if i go with any type of prefix then if they type 20mg first for example then it wouldn't work.

Could someone offer some guidance, i've been tweaking for weeks and i'm no closer.

My index setup,

```auto
{
  "product" : {
    "settings" : {
      "index" : {
        "max_ngram_diff" : "20",
        "number_of_shards" : "5",
        "provided_name" : "product",
        "creation_date" : "1658446282055",
        "analysis" : {
          "analyzer" : {
            "autocomplete_filter" : {
              "filter" : ["lowercase"],
              "type" : "custom",
              "tokenizer" : "edge_ngram"
            }
          },
          "tokenizer" : {
            "edge_ngram" : {
              "type" : "ngram",
              "min_gram" : "1",
              "max_gram" : "20"
            }
          }
        },
        "number_of_replicas" : "1",
        "uuid" : "RceygODWR7CARoQXvSYPqg",
        "version" : {
          "created" : "135238227"
        }
      }
    }
  }
}

{
  "product" : {
    "mappings" : {
      "properties" : {
        "appId" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "isNMP" : {
          "type" : "long"
        },
        "productName" : {
          "type" : "text",
          "analyzer" : "autocomplete_filter",
          "search_analyzer" : "standard"
        },
        "sortOrder" : {
          "type" : "long"
        },
        "title" : {
          "type" : "text",
          "norms" : false
        },
        "vppId" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        }
      }
    }
  }
}

```

My search;

```auto
GET product/_search
{
  "sort": { "_score": "desc" },
  "query": {
    "multi_match": {
      "query": "omep",
      "type": "bool_prefix",
      "fields": [
        "productName",
        "productName._2gram",
        "productName._3gram",
        "productName._4gram"
      ]
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![samtwilliams](https://avatars.discourse-cdn.com/v4/letter/s/f07891/32.png) [@samtwilliams](https://discuss.elastic.co/u/samtwilliams)\
**Post date:** [August 23, 2022, 6:47pm UTC](https://discuss.elastic.co/t/search-as-you-type-with-100k-rows-help-scoring/312412/2 "2022-08-23T18:47:04Z")

</div>

Can anyone offer any advice on this, still struggling

---

<div class="post-metadata">

**Author:** ![BenB196](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/benb196/32/83401_2.png) [@BenB196](https://discuss.elastic.co/u/BenB196)\
**Post date:** [August 24, 2022, 11:59am UTC](https://discuss.elastic.co/t/search-as-you-type-with-100k-rows-help-scoring/312412/3 "2022-08-24T11:59:47Z")

</div>

I'm not too familiar with this kind of use case (so take my advice with some caution), but I'm kind of curious as to why for your `productName` field, you're using `"type": "text"` mapping, rather than `"type": "search_as_you_type"` ([Search-as-you-type field type | Elasticsearch Guide [8.3] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-as-you-type.html)).

You could then also leverage using `"fields": ["productName._index_prefix"]` which I would assume should help getting you a higher score for what you're looking for.

---

<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:** [September 21, 2022, 12:00pm UTC](https://discuss.elastic.co/t/search-as-you-type-with-100k-rows-help-scoring/312412/4 "2022-09-21T12:00:16Z")

</div>

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