# How to combine queries of must & suggest in search request?

**URL:** <https://discuss.elastic.co/t/how-to-combine-queries-of-must-suggest-in-search-request/135236>\
**Category:** Elasticsearch\
**Created:** [June 9, 2018, 6:29pm UTC](https://discuss.elastic.co/t/how-to-combine-queries-of-must-suggest-in-search-request/135236 "2018-06-09T18:29:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vasanth\_kumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vasanth_kumar/32/101447_2.png) [@vasanth\_kumar](https://discuss.elastic.co/u/vasanth_kumar)\
**Post date:** [June 9, 2018, 6:29pm UTC](https://discuss.elastic.co/t/how-to-combine-queries-of-must-suggest-in-search-request/135236/1 "2018-06-09T18:29:48Z")

</div>

Hi,  
How to combine queries of must & suggest with only matching id? I'll explain detail in example,

PUT map\_index  
{  
"mappings": {  
"composite": {  
"properties": {  
"id": {  
"type": "keyword"  
},  
"title\_suggest": {  
"type": "completion"  
}  
}  
}  
}  
}

PUT map\_index/composite/doc1  
{  
"id": "s1",  
"title\_suggest": "kissan\_trigger\_450\_ml"  
}

PUT map\_index/composite/doc2  
{  
"id": "s2",  
"title\_suggest": "kissan\_trigge"  
}

PUT map\_index/composite/doc3  
{  
"id": "s1",  
"title\_suggest": "trigge"  
}

So when I search for,

POST map\_index/composite/\_search  
{

```
"query": {
"bool": {
  "must": [
    {
      "term": {"id":"s1"}
    }
  ]
}

```

},  
"suggest": {  
"title-suggest": {  
"prefix": "kissan",  
"completion": {  
"field": "title\_suggest",  
"skip\_duplicates":true  
}  
}  
}  
}

result as,

{  
"took": 1,  
"timed\_out": false,  
"\_shards": {  
"total": 5,  
"successful": 5,  
"skipped": 0,  
"failed": 0  
},  
"hits": {  
"total": 2,  
"max\_score": 0.2876821,  
"hits": [  
{  
"\_index": "map\_index",  
"\_type": "composite",  
"\_id": "doc1",  
"\_score": 0.2876821,  
"\_source": {  
"id": "s1",  
"title\_suggest": "kissan\_trigger\_450\_ml"  
}  
},  
{  
"\_index": "map\_index",  
"\_type": "composite",  
"\_id": "doc3",  
"\_score": 0.2876821,  
"\_source": {  
"id": "s1",  
"title\_suggest": "trigge"  
}  
}  
]  
},  
"suggest": {  
"title-suggest": [  
{  
"text": "kissan",  
"offset": 0,  
"length": 6,  
"options": [  
{  
"text": "kissan\_trigge",  
"\_index": "map\_index",  
"\_type": "composite",  
"\_id": "doc2",  
"\_score": 1,  
"\_source": {  
"id": "s2",  
"title\_suggest": "kissan\_trigge"  
}  
},  
{  
"text": "kissan\_trigger\_450\_ml",  
"\_index": "map\_index",  
"\_type": "composite",  
"\_id": "doc1",  
"\_score": 1,  
"\_source": {  
"id": "s1",  
"title\_suggest": "kissan\_trigger\_450\_ml"  
}  
}  
]  
}  
]  
}  
}

The response contains results **doc1** & **doc3** matched for 'must' query and 'suggest' contains **doc1** & **do2**. So my question is, is there way to combine these queries like (id + title\_suggest) so that i'll get **doc1** as only result because it only matches both id('s1') & title\_suggest('kissan').

---

<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 7, 2018, 6:29pm UTC](https://discuss.elastic.co/t/how-to-combine-queries-of-must-suggest-in-search-request/135236/2 "2018-07-07T18:29:52Z")

</div>

Closed on July 7, 2018, 6:29pm UTC

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