我有以下短语:
从来没有发生在我身上 - 巴塞罗那的梅西球员对克里斯蒂亚诺罗纳尔多的真实明星 马德里感谢尤文球迷的欢呼。
一个名为Player
的简单弹性搜索文档:
"firstName": {
"localizedValues": {
"de": "",
"en": "Cristiano"
}
},
"lastName": {
"localizedValues": {
"de": "",
"en": "Ronaldo"
}
}
"teamAssociations": [
{
"active": true,
"teamName": {
"localizedValues": {
"de": "",
"en": "Real Madrid"
}
}
]
我尝试做的是一种简单的映射方法, 尝试找一个为球队效力的球员,在这种情况下我想得到克里斯蒂亚诺罗纳尔多和梅西,如果找到了那个短语中的球队,那么就可以提高得分以获得更多相关性。
到目前为止我尝试过:
{
"query": {
"bool": {
"must": {
"multi_match" : {
"query": " It's never happened to me – Messi to Cristiano Ronaldo star of Real Madrid thanks Juve fans for ovation ",
"fields": [ "firstName.localizedValues.*", "lastName.localizedValues.*", "teamAssociations.teamName.*^3" ],
"type": "cross_fields",
"analyzer": "english"
}
}
}
}
}
但是那也是其他为Read Madrid效力的球员,我不想要。 同样在那个标题中我可能没有球队名称,只有球员,因此球队应该是可选的,但如果找到则很重要。
我该如何解决这个问题?
提前感谢您的帮助。
答案 0 :(得分:0)
我们的想法是在should子句中添加可选字段。试试这样的事情
{
"query": {
"bool": {
"must": {
"multi_match": {
"query": " It's never happened to me – Messi to Cristiano Ronaldo star of Real Madrid thanks Juve fans for ovation ",
"fields": [
"firstName.localizedValues.*",
"lastName.localizedValues.*"
],
"type": "cross_fields",
"analyzer": "english"
}
},
"should": {
"multi_match": {
"query": " It's never happened to me – Messi to Cristiano Ronaldo star of Real Madrid thanks Juve fans for ovation ",
"fields": [
"teamAssociations.teamName.*"
],
"type": "cross_fields",
"analyzer": "english"
}
}
}
}
}
如果您需要特定因素,请查看此https://www.elastic.co/guide/en/elasticsearch/guide/current/_boosting_query_clauses.html