Elasticsearch:_score总是0表示tf()

时间:2016-05-18 16:12:15

标签: elasticsearch groovy frequency term

我有这种时髦的剧本:

_index[field][term].tf()

我正在索引这个groovy脚本

POST /_scripts/groovy/getTF
{
     "script": "_index[field][term].tf()"
}

然后运行以下查询始终将_score返回为零(检测命令)

POST /my_index/document/_search
{
  "query": {
    "function_score": {
      "query": {
        "match": {
          "text": "algorithms"
        }
      },
      "functions": [
        {
          "script_score": {
            "script_id": "getTF",
            "lang" : "groovy",
            "params": {
              "term": "algorithms",
              "field": "text"
            }
          }
        }
      ],
      "boost_mode": "replace"
    }
  },
  "size": 10,
  "fields": ["text"]
}

我在这里做错了什么?

这是字段的映射

PUT /ap_dataset/document/_mapping
{
  "document": {
    "properties": {
      "docno": {
        "type": "string",
        "store": true,
        "index": "not_analyzed"
      },
      "text": {
        "type": "string",
        "store": true,
        "index": "analyzed",
        "term_vector": "with_positions_offsets_payloads",
        "analyzer": "my_english"
      }
    }
  }
}

1 个答案:

答案 0 :(得分:0)

0术语频率的解释是在索引中找不到您要查找的术语。您的脚本会收到名为algorithms的术语(复数形式)。

english分析器正在将复数变为单数,这是英语词干的结果。因此,即使您的文字包含algorithms,索引中的字词也是algorithm _index['text']['algorithms']无法找到。