# Query\_String queries with terms boost

**URL:** <https://discuss.elastic.co/t/query-string-queries-with-terms-boost/90508>\
**Category:** Elasticsearch\
**Created:** [June 22, 2017, 5:52pm UTC](https://discuss.elastic.co/t/query-string-queries-with-terms-boost/90508 "2017-06-22T17:52:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicholas\_Ventimiglia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nicholas_ventimiglia/32/16383_2.png) [@Nicholas\_Ventimiglia](https://discuss.elastic.co/u/Nicholas_Ventimiglia)\
**Post date:** [June 22, 2017, 5:52pm UTC](https://discuss.elastic.co/t/query-string-queries-with-terms-boost/90508/1 "2017-06-22T17:52:38Z")

</div>

I have a simple user search working in elastic using the query string command and wildcard query. I would like to improve this query by giving weights to some users based on additional input . Specifically, I want 'friends' of the user to be given a higher priority.

My current query looks like this.

```
{
  "from": 0,
  "size": 100,
  "query": {
    "query_string": {
      "query": "*{UserInput}*",
      "fields": [
        "DisplayName",
        "Name"
      ]
    }
  }
}

```

I imagine I need to use a multi query with a boost as described here : [https://www.elastic.co/guide/en/elasticsearch/guide/current/multi-query-strings.html](https://www.elastic.co/guide/en/elasticsearch/guide/current/multi-query-strings.html)

What I am not getting is how to include my isFriend argument into the query string. I imagine my isfriend argument will need to be some sort of terms query, where I pass in an array of friend Ids.

e.g.

```
{
	"query":
		{
			"terms":
			{
				"UserId" : ["666", "666", "666"]
			}
		}
}

```

My hypothetical final query might look like this.

```
{
   "query": {
      "bool": {
         "should": [
            {
				/* my query string, this is a required match */
               "query_string": {
			      "query": "*{UserInput}*",
			      "fields": [
			        "DisplayName",
			        "Name"
			      ]
			    }
            },
            {
				/* boost my friends, this should be optional */
				"terms":
				{
					"UserId" : ["{UserInput}", "{UserInput}", "{UserInput}"]
				},
				"boost": 1,
            }
         ]
      }
   }
}
```

---

<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 20, 2017, 5:52pm UTC](https://discuss.elastic.co/t/query-string-queries-with-terms-boost/90508/2 "2017-07-20T17:52:55Z")

</div>

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