我在elasticsearch中遇到Functional_scoring问题。当我尝试从Node.js运行功能评分查询时,它总是给我错误
Trace: [illegal_argument_exception] request [/_search] contains unrecognized parameter: [query]
at Logger.trace (/Users/rajeshjain/projects/search/logger.js:39:42)
at elasticClient.instance.search.then.catch.e (/Users/rajeshjain/projects/search/search/disc_cube_topic.js:117:28)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
我要运行的functional_scope查询是
{
"from": "0",
"size": "20",
"query": {
"function_score": {
"query": {
"multi_match": {
"query": "Devel",
"analyzer": "standard",
"fields": [
"topic_name",
"cube_name"
]
}
},
"script_score": {
"script": {
"source": "Math.log1p(10*doc['num_cube_members'].value + 5*doc['message_count'].value + doc['num_topic_members'].value)"
}
}
}
}
}
和试图运行它的节点js代码是
elasticClient.instance.search(query).then(eres => {
// 3. reformat elasticsearch response and send to client.
let response = {
total: eres.hits.total,
extracted: eres.hits.hits.length,
results: []
};
elasticHitResult4DiscoverableTopicCubes(eres.hits.hits).then(results => {
response.results = results;
res.status(200).send(response);
});
})
似乎给我与正在与functional_query一起使用的查询有关的错误...而当我在kibana上运行相同的查询时..它给了我适当的结果。
答案 0 :(得分:1)
我自己解决了这个问题。区别是..来自nodejs的搜索api希望将body作为请求的一部分。.与原始有问题的json进行比较时,我添加了body标签。
{
"from": "0",
"size": "20",
"body": {
"query": {
"function_score": {
"query": {
"multi_match": {
"query": "Devel",
"analyzer": "standard",
"fields": [
"topic_name",
"cube_name"
]
}
},
"script_score": {
"script": {
"source": "Math.log1p(10*doc['num_cube_members'].value + 5*doc['message_count'].value + doc['num_topic_members'].value)"
}
}
}
}
}
}