# Logstash to create the complete suggester

**URL:** <https://discuss.elastic.co/t/logstash-to-create-the-complete-suggester/77102>\
**Category:** Logstash\
**Created:** [March 2, 2017, 7:21am UTC](https://discuss.elastic.co/t/logstash-to-create-the-complete-suggester/77102 "2017-03-02T07:21:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Greentea](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/greentea/32/15924_2.png) [@Greentea](https://discuss.elastic.co/u/Greentea)\
**Post date:** [March 2, 2017, 7:21am UTC](https://discuss.elastic.co/t/logstash-to-create-the-complete-suggester/77102/1 "2017-03-02T07:21:54Z")

</div>

Hi!  
I am going to make completion suggester in my search page, I used the display\_name as the text, and I would like to insert id as the weight for sorting the suggester.  
Here is my logstash filter

```
filter {
if [type] == "product"{
	mutate {
		add_field => { "product_suggest" => "%{display_name}" }
		add_field => { "weight" => "%{id}" }
		add_field => { "product_suggester" => "%{display_name}" }
		remove_field => ["attribute_value_en", "attribute_value_sc"]
	}
}
if [type] == "merchant"{
	mutate {
		add_field => { "merchant_suggest" => "%{merchant_name}" }
		add_field => { "weight" => "%{id}" }
		add_field => { "merchant_suggester" => "%{merchant_name}" }
	}
}
}

```

Here is the example I try to write

```
PUT music/song/1?refresh
{
"suggest" : [
    {
        "input": "Nevermind",
        "weight" : 10
    },
    {
        "input": "Nirvana",
        "weight" : 3
    }
]
}
```

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [March 2, 2017, 7:25am UTC](https://discuss.elastic.co/t/logstash-to-create-the-complete-suggester/77102/2 "2017-03-02T07:25:25Z")

</div>

I don't understand what you're trying to do. How is Logstash related to the search form completion feature on your web page? And what exact problem are you facing?

---

<div class="post-metadata">

**Author:** ![Greentea](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/greentea/32/15924_2.png) [@Greentea](https://discuss.elastic.co/u/Greentea)\
**Post date:** [March 2, 2017, 7:28am UTC](https://discuss.elastic.co/t/logstash-to-create-the-complete-suggester/77102/3 "2017-03-02T07:28:33Z")

</div>

In the example,  
the **Nevermind** is the suggester with **weight** 10.

And I am going to use logstash to make  
the **display\_name** as the suggester with **wight** follow the id

---

<div class="post-metadata">

**Author:** ![Greentea](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/greentea/32/15924_2.png) [@Greentea](https://discuss.elastic.co/u/Greentea)\
**Post date:** [March 2, 2017, 8:18am UTC](https://discuss.elastic.co/t/logstash-to-create-the-complete-suggester/77102/4 "2017-03-02T08:18:02Z")

</div>

I find that it works with the following filter

```
filter {
if [type] == "product"{
	mutate {
		add_field => { "[product_suggest][input]" => "%{display_name}"}
		add_field => { "[product_suggest][weight]" => "%{id}"}
		remove_field => ["attribute_value_en", "attribute_value_sc"]
	}
}
if [type] == "merchant"{
	mutate {
		add_field => { "[merchant_suggest][input]" => "%{merchant_name}"}
		add_field => { "[merchant_suggest][weight]" => "%{id}"}
	}
    }
}
```

---

<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 30, 2017, 8:18am UTC](https://discuss.elastic.co/t/logstash-to-create-the-complete-suggester/77102/5 "2017-03-30T08:18:44Z")

</div>

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