# How to create a live search option using elastic search

**URL:** <https://discuss.elastic.co/t/how-to-create-a-live-search-option-using-elastic-search/167220>\
**Category:** Elasticsearch\
**Created:** [February 6, 2019, 5:30am UTC](https://discuss.elastic.co/t/how-to-create-a-live-search-option-using-elastic-search/167220 "2019-02-06T05:30:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pathum\_Kalhan](https://avatars.discourse-cdn.com/v4/letter/p/a183cd/32.png) [@Pathum\_Kalhan](https://discuss.elastic.co/u/Pathum_Kalhan)\
**Post date:** [February 6, 2019, 5:30am UTC](https://discuss.elastic.co/t/how-to-create-a-live-search-option-using-elastic-search/167220/1 "2019-02-06T05:30:16Z")

</div>

I am new to elastic search and playing around with in it. I created an index called live\_search\_index then I add documents contain these title fields.

- Western province
- Northern province
- Colombo district
- Colombo city
- Negambo city

If I run this query

```auto
{
    "query": {
        "match" : {
            "title" : "colombo"
    }
}
}

```

If I run this query I will get `colombo district` and `colombo city` But this query gives me nothing.

```auto
{
    "query": {
        "match" : {
            "title" : "mbo"
    }
}
}

```

What I want is pass "mbo" and get the result of

Colo **mbo** district

Colo **mbo** city

Nega **mbo** city

How do I achieve this using elastic search?

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [February 6, 2019, 5:48am UTC](https://discuss.elastic.co/t/how-to-create-a-live-search-option-using-elastic-search/167220/2 "2019-02-06T05:48:33Z")

</div>

Have a read of the section on [analysis](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis.html) first.

You'll want to configure an analyzer for the `"title"` field that generates [edge ngrams](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-edgengram-tokenfilter.html) from the back of tokens. Typically, you would

1. reverse the token
2. generate the edge ngram
3. reverse the resulting edge ngram.

For example, given the text `"Colombo district"`, the [Standard tokenizer](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-standard-tokenizer.html) will produce tokens `Colombo` and `district`. In the token filters, we would want to

1. [lowercase](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-lowercase-tokenfilter.html) to support case insensitive search: `colombo` and `district`
2. [reverse](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-reverse-tokenfilter.html) tokens in preparation for back edge ngram: `obmoloc` and `tcirtsid`
3. [edgengram](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-edgengram-tokenfilter.html) to create ngram. for purposes here, min and max gram set to 3: `obmoloc`, `obm`, `tci` and `tcirtsid`
4. [reverse](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-reverse-tokenfilter.html) tokens again: `colombo`, `mbo`, `ict` and `district`

---

<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:** [March 6, 2019, 5:48am UTC](https://discuss.elastic.co/t/how-to-create-a-live-search-option-using-elastic-search/167220/3 "2019-03-06T05:48:35Z")

</div>

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