I have a query that I can't quite get to return the most relevant answer.
If I search for 'herp' the result is
preferably I would like this order
So the question I have, I guess is: How do I get terms in the beginning of a sequence of words get higher score than one appearing nearer the end?
the analyser I use look like this:
"analyzer":[
"autocomplete":[
"type":"custom",
"tokenizer":"standard",
"filter":[
"standard",
"lowercase",
"stop",
"edgeNGramAlpha"
]
],
"filter":[
"edgeNGramAlpha":[
"type":"edgeNGram",
"min_gram":1,
"max_gram":20
]
]
]
and the mapping looks like this (loots of field but alla look the same)
"name": [
"type": "multi_field",
"fields" : [
"untouched": [
"type": "string",
"index": "not_analyzed"
],
"name": [
"type": "string"
],
"autocomplete": [
"analyzer":"${language}_autocomplete",
"type":"string",
]
]
]
and the query look like this:
{
"from": 0,
"size": 10,
"query": {
"filtered": {
"query": {
"multi_match": {
"query": "herp",
"fields": [
"name^8",
"name.autocomplete^4",
"historic_name.autocomplete"
],
"type": "cross_fields",
"operator": "AND",
"analyzer": "standard"
}
}
}
}
}
One way to achieve this would be to provide an additional boost for terms at the beginning of the field using span first
Example :
{
"from": 0,
"size": 10,
"query": {
"bool": {
"disable_coord": true,
"must": [
{
"multi_match": {
"query": "herp",
"fields": [
"name^8",
"name.autocomplete^4",
"historic_name.autocomplete"
],
"analyzer": "standard"
}
}
],
"should": [
{
"span_first": {
"match": {
"span_term": {
"name": "herp"
}
},
"end": 1,
"boost": 1
}
},
{
"span_first": {
"match": {
"span_term": {
"historic_name": "herp"
}
},
"end": 1,
"boost": 1
}
}
],
"minimum_number_should_match": 0
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.