# A little help getting started with ngram

**URL:** <https://discuss.elastic.co/t/a-little-help-getting-started-with-ngram/125010>\
**Category:** Elasticsearch\
**Created:** [March 21, 2018, 2:48pm UTC](https://discuss.elastic.co/t/a-little-help-getting-started-with-ngram/125010 "2018-03-21T14:48:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bhulsman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bhulsman/32/29096_2.png) [@bhulsman](https://discuss.elastic.co/u/bhulsman)\
**Post date:** [March 21, 2018, 2:48pm UTC](https://discuss.elastic.co/t/a-little-help-getting-started-with-ngram/125010/1 "2018-03-21T14:48:00Z")

</div>

Just yesterday I started working with ElasticSearch and I'm pretty happy with how it works. There are just a few things I can't get my head wrapped around yet. See the situation below:

```auto
{id: 5, name: "Lorem ipsum dolor sit amet", number: "180005", customer: "Lorem ipsum", archived: false}
{id: 19, name: "New order", number: "180019", customer: "Lorem ipsum", archived: false}
{id: 27, name: "Businesscards", number: "180027", customer: "Lorem ipsum", archived: false}

```

When searching for 'Buisinesscards' (the exact name of record 27), the other two records have a higher score and are on top of the list.

I'm using a simple ngram setup like this:

**Settings:**

```auto
"analysis"=> [
    "filter"=> [
        "ngram_filter"=> [
        "type"=> "ngram",
        "min_gram"=> 2,
        "max_gram"=> 20
        ]
    ],
    "analyzer"=> [
        "ngram_analyzer"=> [
            "type"=> "custom",
            "tokenizer"=> "standard",
            "filter"=> [
                "lowercase",
                "ngram_filter"
            ]
        ]
    ]
],

```

**Mapping:**

```auto
'properties' => [
    'id' => [
        'type' => 'integer',
        'index' => false,
    ],
    'name' => [
        'type' => 'text',
        'analyzer' => 'ngram_analyzer',
    ],
    'number' => [
        'type' => 'text',
    ],
    'customer' => [
        'type' => 'text',
        'analyzer' => 'ngram_analyzer',
    ],
    'archived' => [
        'type' => 'boolean',
    ],
]

```

**Search:**

```auto
'must' => [
    'multi_match' => [
        'query' => $this->builder->query,
        'fields' => ['name', 'number', 'customer'],
    ]
]

```

What can I do to to get the record with the name 'Businesscards' at the top when searching for "businesscards"?

---

<div class="post-metadata">

**Author:** ![bhulsman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bhulsman/32/29096_2.png) [@bhulsman](https://discuss.elastic.co/u/bhulsman)\
**Post date:** [March 21, 2018, 3:04pm UTC](https://discuss.elastic.co/t/a-little-help-getting-started-with-ngram/125010/2 "2018-03-21T15:04:06Z")

</div>

Been screwing around with it a bit more, and it seems that adjusting `min_gram` to 3 and `max_gram` to 4 does the trick for me.

---

<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:** [April 18, 2018, 3:04pm UTC](https://discuss.elastic.co/t/a-little-help-getting-started-with-ngram/125010/3 "2018-04-18T15:04:19Z")

</div>

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