有没有办法增强从has_parent
查询“出现”的文档?
{
"query": {
"function_score": {
"query": {
"bool": {
"should": [
{
"multi_match": {
"fields": ["name^3", "tags^2", "content"],
"query": "xx"
}
},
{
"has_parent": {
"type": "theparent",
"query": {
"multi_match": {
"type": "best_fields",
"fields": ["name^5", "content"],
"query": "xx"
}
}
}
},
{
"has_child": {
"type": "thechild",
"query": {
"multi_match": {
"fields": ["name^3","content"],
"query": "xx"
}
}
}
}
]
}
},
"score_mode": "sum",
"functions": [
{
"linear": {
"date": {
"origin": "2014-08-29",
"scale": "700d",
"decay": 0.6
}
}
}
]
}
}
更确切地说,我只想在查询与父项的名称字段匹配时提升这些文档
(我还没有找到一种方法来引用
functions
中的父字段,即theparent._source.name ~= "xx"
)
最佳答案
根据sources from Github (see line 104),boost
查询中允许使用has_parent
参数。
基于此属性,可以专门增强包含should
查询的has_parent
子句。在您的情况下,结果将是:
...
{
"has_parent": {
"type": "theparent",
"query": {
"multi_match": {
"type": "best_fields",
"fields": ["name^5", "content"],
"query": "xx"
}
},
"boost": 5
}
}
...
我不知道它是否可以为您提供帮助,但是您会发现有关增强查询子句here的更多见解。
关于elasticsearch - elasticsearch:在has_parent查询中增强文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25573103/