弹性搜索错误 - 变量 [相关性] 未定义

装甲坦克

我正在尝试查询我的产品 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 -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"
    }
  }
}
'

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章