I am doing a multi-match search using the following query object using script_score
:
{
_source: [
'baseline',
'cpcr',
'date',
'description',
'dev_status',
'element',
'event',
'id'
],
track_total_hits: true,
query: {
script_score: {
query: {
bool: {
filter: []
},
},
script: {
source: "def v=doc['description'].value; def score = 10000; score += v.length(); score -= " + "\"" + searchObject.query + "\"" + ".indexOf(v)*50;", // throws error
params: { highlights: 3 }
}
}
},
highlight: { fields: { '*': {} } },
sort: [],
from: 0,
size: 50
}
I'd like the results to be ordered by their number of highlight matches. For instance the first record would have 5 < em >'s, second record would have 4 < em > matches and so on. Currently my results aren't sorted this way.
elasticsearch.config.ts
"settings": {
"analysis": {
"analyzer": {
"search_synonyms": {
"tokenizer": "whitespace",
"filter": [
"graph_synonyms",
"lowercase",
"asciifolding"
],
}
}
}
},
"mappings": {
"properties": {
"description": {
"type": "text",
"analyzer": "search_synonyms"
},
"narrative": {
"type":"object",
"properties":{
"_all":{
"type": "text",
"analyzer": "search_synonyms"
}
}
},
}
}