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

时间:2017-05-21 10:14:26

标签: elasticsearch lucene

我使用以下设置和映射索引85,000个文档:

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

0 个答案:

没有答案