[英]Elasticsearch : How to sort by max number should match
I have the following Elasticsearch content, basically a list of user with nested skills require 我有以下Elasticsearch内容,基本上是具有嵌套技能的用户列表
Elasticsearch mapping from my index 我索引中的Elasticsearch映射
{
worker:{
dynamic:"false",
properties: {
skills: {
type:"nested",
properties:{
name:{
type:"text"
},
id:{
type:"text"
}
}
}
}
}
}
and my simple data for users : 和我为用户提供的简单数据:
{
"first_name": "Samir",
"last_name": "Yundt",
"skills":[
{
"id": 1,
"name": "HTML"
},
{
"id": 1,
"name": "Javascript"
}
]
},
{
"first_name": "Kaley",
"last_name": "Fadel",
"skills":[
{
"id": 1,
"name": "HTML"
},
{
"id": 1,
"name": "CSS"
}
]
}
My ES query : 我的ES查询:
{
query:{
bool:{
should:[
{
nested:{
path:"sub_processes",
query:{
bool:{
should:[
{
match:{
"skills.name": "HTML"
}
},
{
match:{
"skills.name": "CSS"
}
}
}
]
}
}
}
}
]
}
}
}
So how can I sort user by the max number skill match ? 那么如何按最大人数技能匹配对用户进行排序? I found some documentation recommend use boost but it's not impossible because my input(skill name) is dynamic.
我发现一些文档建议使用Boost,但这并非不可能,因为我的输入(技能名称)是动态的。 Thanks all
谢谢大家
You could use constant_score to give a fixed score per skill. 您可以使用constant_score给出每个技能的固定分数。 Here is an example :
这是一个例子:
{
"query": {
"bool": {
"should": [
{
"constant_score": {
"boost": 1,
"query": {
"match": {
"skills.name": "HTML"
}
}
}
},
{
"constant_score": {
"boost": 1,
"query": {
"match": {
"skills.name": "CSS"
}
}
}
}
]
}
}
}
This way, you will get N score point per skill. 这样,您将获得每项技能N分的分数。 Your results will be naturally sort by skills count.
您的结果将自然按照技能计数排序。
Because of queryNorm, N will be different than 1 for more than 2 tags (but 2 matching will be always strong than 1, 3 stronger than 2, etc ... no matters the tag). 由于使用了queryNorm,对于2个以上的标签,N会不同于1(但是2个匹配项始终会比1强,而3个匹配会比2强,依此类推……与标签无关)。 If you want an exact score per field, you can have a look to the keyword datatype .
如果您想要每个字段的准确分数,可以查看关键字datatype 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.