我正在使用以下查询对象进行多重匹配搜索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
}
我希望结果按其突出显示匹配的数量排序。例如,第一条记录将有 5 个< em >,第二条记录将有 4 个< em >匹配,依此类推。目前我的结果不是这样排序的。
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"
}
}
},
}
}