elasticsearch ElasticSearch-用自定义评分替换评分系统,elasticsearch,lucene,elasticsearch,Lucene" /> elasticsearch ElasticSearch-用自定义评分替换评分系统,elasticsearch,lucene,elasticsearch,Lucene" />

elasticsearch ElasticSearch-用自定义评分替换评分系统

elasticsearch ElasticSearch-用自定义评分替换评分系统,elasticsearch,lucene,elasticsearch,Lucene,我正在使用以下设置和映射索引85000个文档: PUT /ap_dataset/ { "settings": { "index": { "store": { "type": "fs" }, "number_of_shards": 1, "number_of_replicas": 1 }, "analysis": { "analyzer": { "my_english": { "type": "english", "stopwords_

我正在使用以下设置和映射索引85000个文档:

PUT /ap_dataset/
{
"settings": {
"index": {
  "store": {
    "type": "fs"
  },
  "number_of_shards": 1,
  "number_of_replicas": 1
},
"analysis": {
  "analyzer": {
    "my_english": { 
      "type": "english",
      "stopwords_path": "stoplist.txt" 
    }
   }
  }
 }
}

PUT /ap_dataset/hw1/_mapping
{
"hw1": {
"properties": {
  "docno": {
    "type": "keyword",
    "store": true
  },
  "text": {
    "type": "text",
    "store": true,
    "term_vector": "with_positions_offsets_payloads",
    "analyzer": "my_english",
    "fielddata": true

   }
  }
 }
}
我使用的是ElasticSearch 5.4。我尝试以下列方式将默认评分替换为自定义评分:

GET /ap_dataset/document/_search
{
"query": {
"function_score": {
  "query": {
    "match": {
      "text": "cow"
    }
  },
  "boost_mode": "replace",
  "functions": [
    {
      "script_score": {
        "script": "_index['text']['cow'].tf()"
      }
    }
   ]
  }
 }
}
但我得到了以下错误:

 {
 "error": {
"root_cause": [
  {
    "type": "script_exception",
    "reason": "compile error",
    "script_stack": [
      "_index['text']['fox'].tf( ...",
      "^---- HERE"
    ],
    "script": "_index['text']['fox'].tf()",
    "lang": "painless"
  }
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
  {
    "shard": 0,
    "index": "ap_dataset",
    "node": "zhCmVrZgRC-YQU5BOaz49w",
    "reason": {
      "type": "query_shard_exception",
      "reason": "script_score: the script could not be loaded",
      "index_uuid": "-TpUstdDQVSZnLwvLKWkPA",
      "index": "ap_dataset",
      "caused_by": {
        "type": "script_exception",
        "reason": "compile error",
        "script_stack": [
          "_index['text']['fox'].tf( ...",
          "^---- HERE"
        ],
        "script": "_index['text']['fox'].tf()",
        "lang": "painless",
        "caused_by": {
          "type": "illegal_argument_exception",
          "reason": "Variable [_index] is not defined."
        }
      }
    }
  }
 ]
},
"status": 400
}
对这个问题有什么建议吗?
TIA

这是一个编译错误。你确定_index是一些可访问的属性吗?这是5.4版本下的一个问题,从5.5版开始,他们将对访问_index字段发出警告。我设法用groovy脚本解决了这个问题。