gpt4 book ai didi

elasticsearch - Elasticsearch 错误- undefined variable [相关性]

转载 作者:行者123 更新时间:2023-12-03 00:47:41 26 4
gpt4 key购买 nike

我正在尝试查询我的产品ElasticSearch索引并创建一个script_score,但我一直收到错误Variable [relevancy] is not defined.
我尝试只用一个数字替换脚本,然后用Math.log(_score)替换,以确保script_score正常运行并且数学函数正常,并且两个查询均按预期执行。我也尝试了doc['relevancy'].value并收到了同样的错误。

我的查询是:

curl -X GET "localhost:9200/products/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": {
"function_score": {
"query": {
"multi_match" : {
"query": "KQ",
"fields": [ "item_id", "extended_desc", "mfg_part_no" ]
}
},
"script_score" : {
"script": "Math.log(_score) + Math.log(doc['relevancy'])"
},
"boost_mode": "replace"
}
}
}
'

该索引的映射为:
{
"products" : {
"mappings" : {
"properties" : {
"@timestamp" : {
"type" : "date"
},
"@version" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"extended_desc" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"frecno" : {
"type" : "long"
},
"item_id" : {
"type" : "text",
"analyzer" : "my_analyzer"
},
"mfg_part_no" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"relevancy" : {
"type" : "long"
}
}
}
}
}

最佳答案

'替换了\u0027,因为这是 curl 的。

curl -X GET "localhost:9200/products/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": {
"function_score": {
"query": {
"multi_match" : {
"query": "KQ",
"fields": [ "item_id", "extended_desc", "mfg_part_no" ]
}
},
"script_score" : {
"script": "Math.log(_score) + Math.log(doc[\u0027relevancy\u0027].value)"
},
"boost_mode": "replace"
}
}
}
'

关于elasticsearch - Elasticsearch 错误- undefined variable [相关性],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58169891/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com