Reputation: 2073
I have a problem understanding the operation of the boost parameter in Elasticsearch 6.
I have an index with four fields: id, title, content, client. All fields are of type "text".
With the following query I try to give the title field a higher weight:
{
"query": {
"bool": {
"must": [
{
"query_string": {
"query": "europe",
"analyzer": "standard",
"default_operator": "AND",
"fields": [
"id", "title^2", "content"
]
}
},
{
"term": {
"client": {
"value": "test",
"boost": 1
}
}
}
]
}
},
"size": 10,
"from": 0,
"sort": [
{
"_score": {
"order": "desc"
}
}
]
}
What I would expect now would be that I get search results where the first hits are only records that contain the search term in the title, but not necessarily in the content. However, I only get hits that contain the search term in both the title and the content, ie a multi-field matching.
Can I somehow influence this, perhaps by increasing the boost value or reformulating the request? I also read something about a dismax query, but I do not know if that is useful for my purposes?
Upvotes: 0
Views: 743
Reputation: 7221
You need to use a multi match query with the best_fields strategy.
In the multi match syntax you can use the boosting syntax "^X" and you will gain access to different strategies in order to tweak the outcome of your query.
The best_field
strategy tell that between all the searched field, you will only keep the most relevant field for scoring (and not the sum of all the fields, that would favorize document where the query is found in title AND content).
Could you try :
{
"query": {
"bool": {
"must": [
{
"multi_match": {
"query": "europe",
"analyzer": "standard",
"operator": "AND",
"fields": [
"id", "title^2", "content"
],
"type": "best_fields"
}
},
{
"term": {
"client": {
"value": "test",
"boost": 1
}
}
}
]
}
},
"size": 10,
"from": 0,
"sort": [
{
"_score": {
"order": "desc"
}
}
]
}
BTW the best_field
strategy is the default one so you can omit the type
parameter.
Upvotes: 0