elasticsearch - Elasticsearch:执行自定义分数脚本时在映射中找不到字段

标签 elasticsearch groovy groovyscriptengine

我已经为这个问题苦苦挣扎了几个小时。我正在尝试使用脚本分数(常规)在搜索中实现自定义分数。

映射:

{
"properties": {
    "m_skill": {
        "properties": {
            "actual_period": {
                "type": "long"
            },
            "area_display": {
                "type": "string"
            },
            "c": {
                "type": "double"
            },
            "capability": {
                "type": "string"
            },
            "capability_display": {
                "type": "string"
            },
            "order_wt": {
                "type": "double"
            },
            "skillarea": {
                "type": "string"
            },
            "star_wt": {
                "type": "double"
            },
            "w": {
                "type": "double"
            }
            }
        }
    },
    "personid": {
        "type": "string"
    },
    date_of_creation": {
        "type": "long"
    },
    "phone": {
        "properties": {
            "c": {
                "type": "long"
            },
            "v": {
                "type": "string"
            }
        }
    }
}

(m_skill是一个数组)

查询:
{"match_all":{}}

得分脚本:
return doc['m_skill'].values.star_wt.sum()

错误:
No field found for [m_skill] in mapping with types [peopleworld]

但是,当我尝试对“date_of_creation”进行相同操作时,我没有任何异常。
我发现有些人在谈论同一个问题,但是几乎没有任何帖子有回复。有没有人遇到过这样的问题。我究竟做错了什么?

另一个问题,我的公式很复杂,然后我在上面写过。用简单的语言来说,就像当用户要求一组技能时,我选择具有要求技能的文档,然后根据他们的star_wt授予他们一个分数,该分数用于对最终结果集进行排序。使用elasticsearch自定义分数实现相同的想法是一个好主意吗?

任何帮助都将受到欢迎。

最佳答案

您在映射中的“date_of_creation”上缺少双引号。这可能是引起您问题的原因。我已经在此答案中为您添加了经过验证的JSON的映射。

{
   "properties":{
      "m_skill":{
         "properties":{
            "actual_period":{
               "type":"long"
            },
            "area_display":{
               "type":"string"
            },
            "c":{
               "type":"double"
            },
            "capability":{
               "type":"string"
            },
            "capability_display":{
               "type":"string"
            },
            "order_wt":{
               "type":"double"
            },
            "skillarea":{
               "type":"string"
            },
            "star_wt":{
               "type":"double"
            },
            "w":{
               "type":"double"
            }
         }
      }
   },
   "personid":{
      "type":"string"
   },
   "date_of_creation":{
      "type":"long"
   },
   "phone":{
      "properties":{
         "c":{
            "type":"long"
         },
         "v":{
            "type":"string"
         }
      }
   }
}

关于elasticsearch - Elasticsearch:执行自定义分数脚本时在映射中找不到字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42394039/

相关文章:

elasticsearch - Logstash:是否有一种方法可以在迁移时更改文档中的某些属性

elasticsearch - 来自Logstash的Elasticsearch映射配置

java - 使用 Groovy 脚本创建 java 类的实例

elasticsearch - ElasticSearch more_like_this结果集受限制

ruby - 映射ElasticSearch GeoPoint字段

java - 使用 Multi-Tenancy 对 Grails 域类进行单元测试

xml - 使用 Groovy XmlSlurper 查找属性的最大值

android - 在 Android buildTypes-->debug 中设置 `isDebuggable true` 会导致 gradle 同步错误

java - 如何从 jar 文件中加载 groovy 脚本?