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
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,
}
]
}
}
}