# Auto Suggestion on multiple fields

**URL:** <https://discuss.elastic.co/t/auto-suggestion-on-multiple-fields/53858>\
**Category:** Elasticsearch\
**Created:** [June 24, 2016, 7:10am UTC](https://discuss.elastic.co/t/auto-suggestion-on-multiple-fields/53858 "2016-06-24T07:10:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ramz](https://avatars.discourse-cdn.com/v4/letter/r/a183cd/32.png) [@ramz](https://discuss.elastic.co/u/ramz)\
**Post date:** [June 24, 2016, 7:10am UTC](https://discuss.elastic.co/t/auto-suggestion-on-multiple-fields/53858/1 "2016-06-24T07:10:09Z")

</div>

Hello,

Am trying to implement auto suggestion for mutli fields.

here's my mapping:  
{  
"bizz\_suggest": {  
"type": "completion",  
"analyzer": "whitespace",  
"search\_analyzer":"whitespace",  
"payloads": false,  
"preserve\_separators": true,  
"preserve\_position\_increments": true,  
"max\_input\_length": 50  
},  
"cat\_suggest": {  
"type": "completion",  
"analyzer": "whitespace",  
"search\_analyzer":"whitespace",  
"payloads": false,  
"preserve\_separators": true,  
"preserve\_position\_increments": true,  
"max\_input\_length": 50  
}  
}

bizz refers to Business Name  
cat refers to Category Name

So, when trying to search basically suggester should return auto completion from both business and category.

I was able to achieve that for business, but how do i achieve suto suggestion for both the fields.

query:  
"suggest" : {  
"text" : "n",  
"completion" : {  
"field" : "bizz\_suggest"  
}  
}  
}

Is there a posiiblity to get suggester results from both category and auto suggest at a time?

thanks in advance.

regards,  
Ram.

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [June 24, 2016, 9:13am UTC](https://discuss.elastic.co/t/auto-suggestion-on-multiple-fields/53858/2 "2016-06-24T09:13:49Z")

</div>

I think you will need a second suggest field that contains the values from both fields. The completion suggestion works with a single field at the time. You could have the suggest queries in the same request via a bool query, but I think that isn't what you're looking for?

---

<div class="post-metadata">

**Author:** ![ramz](https://avatars.discourse-cdn.com/v4/letter/r/a183cd/32.png) [@ramz](https://discuss.elastic.co/u/ramz)\
**Post date:** [June 24, 2016, 9:26am UTC](https://discuss.elastic.co/t/auto-suggestion-on-multiple-fields/53858/3 "2016-06-24T09:26:54Z")

</div>

Hi Martijn,

here's an example so that it explains what am exactly looking for:

document will be  
{  
"bizzName":"Huston",  
"bizz\_suggest": {  
"weight": 30,  
"input": [  
"huston"  
],  
"output": "Huston - Hotel"  
},  
"cat\_suggest": {  
"weight": 30,  
"input": [  
"hotel"  
],  
"output": "Hotels"  
}  
}

Now when i type "h" it should return both Huston - Hotel and Hotels so that i can either select only the business or i would go for category.

Any idea how we implement this?

regards,  
ramz

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [June 24, 2016, 12:21pm UTC](https://discuss.elastic.co/t/auto-suggestion-on-multiple-fields/53858/4 "2016-06-24T12:21:48Z")

</div>

I don't see another way then adding another suggest field that contains both business and category names. For example by adding a `general_suggest` field to your documents:

{  
"bizzName": "Huston",  
"bizz\_suggest": {  
"weight": 30,  
"input": [  
"new south wales"  
],  
"output": "Huston - Hotel"  
},  
"cat\_suggest": {  
"weight": 30,  
"input": [  
"hotel"  
],  
"output": "Hotels"  
},  
"general\_suggest" : {  
"input" : ["new south wales", "Hotels"]  
}  
}

---

<div class="post-metadata">

**Author:** ![ramz](https://avatars.discourse-cdn.com/v4/letter/r/a183cd/32.png) [@ramz](https://discuss.elastic.co/u/ramz)\
**Post date:** [June 24, 2016, 12:47pm UTC](https://discuss.elastic.co/t/auto-suggestion-on-multiple-fields/53858/5 "2016-06-24T12:47:31Z")

</div>

Hi Martijn,

thanks for your reply.

i have resolved the issue, here's the query you need to send for auto suggest:

"text": "h",  
"org\_suggest": {  
"completion": {  
"field": "org\_suggest",  
"size" : "10"  
}  
},  
"cat\_suggest": {  
"completion": {  
"field": "cat\_suggest",  
"size" : "6"  
}  
}  
}

regards,  
Ram.

---

<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:** [July 5, 2017, 10:40pm UTC](https://discuss.elastic.co/t/auto-suggestion-on-multiple-fields/53858/6 "2017-07-05T22:40:43Z")

</div>


