我成功地为针对一个索引运行的查询实现了function_score
,但是将函数function_score应用于跨越ElasticSearch 6.2.4中具有不同字段的多个索引的查询。
此查询:
POST /web_document,web_part/_search
{
"from": 0,
"size": 100,
"query": {
"function_score": {
"query": {
"bool": {
"should": [
{
"bool": {
"must": [
{
"multi_match": {
"type": "best_fields",
"query": "sampling probe",
"fields": [
"titleD.autocomplete^5",
"titleE.autocomplete^5"
]
}
}
],
"filter": [
{
"term": {
"_index": {
"value": "web_document"
}
}
}
]
}
},
{
"bool": {
"must": [
{
"multi_match": {
"type": "best_fields",
"query": "sampling probe",
"fields": [
"textD.autocomplete^5",
"textE.autocomplete^5"
]
}
}
],
"filter": [
{
"term": {
"_index": {
"value": "web_part"
}
}
}
]
}
}
]
}
},
"functions": [
{
"filter": {
"bool": {
"must_not": [
{ "exists": { "field": "revDestDate" } },
{ "exists": { "field": "mutationDate" } }
]
}
},
"script_score": {
"script": "100"
}
},
{
"filter": {
"term": {
"_index": "web_part"
}
},
"gauss": {
"mutationDate": {
"origin": "now",
"scale": "90d",
"decay": 0.5
}
},
"weight": 20
},
{
"filter": {
"term": {
"_index": "web_document"
}
},
"gauss": {
"revDestDate": {
"origin": "now",
"scale": "90d",
"decay": 0.5
}
},
"weight": 20
}
],
"score_mode" : "first",
"boost_mode": "sum"
}
}
}
返回以下错误:
{
"error": {
…
"failed_shards": [
{
"index": "web_document",
…
"reason": {
"type": "parsing_exception",
"reason": "unknown field [mutationDate]",
…
}
},
{
"index": "web_part",
…
"reason": {
"type": "parsing_exception",
"reason": "unknown field [revDestDate]",
…
}
}
]
},
"status": 400
}
我还尝试将function_score合并到这样的induvidual查询中, 返回相同的错误:
POST /web_document,web_part/_search
{
"from": 0,
"size": 100,
"query": {
"bool": {
"should": [
{
"function_score": {
"query": {
"bool": {
"must": [
{
"multi_match": {
"type": "best_fields",
"query": "sampling probe",
"fields": [
"titleD.autocomplete^5",
"titleE.autocomplete^5"
]
}
}
],
"filter": [
{
"term": {
"_index": {
"value": "web_document"
}
}
}
]
}
},
"functions": [
{
"gauss": {
"revDestDate": {
"origin": "now",
"scale": "90d",
"decay": 0.5
}
}
}
]
}
},
{
"function_score": {
"query": {
"bool": {
"must": [
{
"multi_match": {
"type": "best_fields",
"query": "sampling probe",
"fields": [
"textD.autocomplete^5",
"textE.autocomplete^5"
]
}
}
],
"filter": [
{
"term": {
"_index": {
"value": "web_part"
}
}
}
]
}
},
"functions": [
{
"gauss": {
"mutationDate": {
"origin": "now",
"scale": "90d",
"decay": 0.5
}
}
}
]
}
}
]
}
}
}
根据Darshan Pratil对此问题的评论answer同样的问题,这在过去的版本中有效。
如何在弹性搜索6.2.4中完成?