简体   繁体   English

Elasticsearch:_score总是0表示tf()

[英]Elasticsearch : _score always 0 for tf()

I have this kind of groovy script: 我有这种时髦的脚本:

_index[field][term].tf()

I am indexing this groovy script 我正在索引这个groovy脚本

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

Then running the following query always returns _score to be zero (sense command) 然后运行以下查询始终返回_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"]
}

What am I doing wrong here? 我在这做错了什么?

This is the mapping for the fields 这是字段的映射

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"
      }
    }
  }
}

The explanation for the 0 term frequency is that the term you are looking for is not found in the index. 0项频率的解释是在索引中找不到您要查找的术语。 Your script receives the term called algorithms (which is plural). 您的脚本接收称为algorithms的术语(复数)。

But the english analyzer is changing plurals to singular, as a result of the english stemmer. english分析器正在将复数变为单数,这是英语词干的结果。 So, even if your text is containing algorithms , the term in the index is algorithm which will not be found by _index['text']['algorithms'] . 所以,即使你的文字包含algorithms ,在索引术语是algorithm ,不会被发现_index['text']['algorithms']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM