2017-02-22 176 views
0

我一直在努力解决这个问题几个小时了。我正在尝试使用脚本分数(groovy)在搜索中实现自定义分数。Elasticsearch:在执行自定义分数脚本时没有映射找到映射

映射:

{ 
"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自定义分数来实现相同的想法是不是一个好主意?

任何帮助将受到很大的欢迎。

回答

0

您在映射中缺少“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" 
     } 
     } 
    } 
} 
+2

感谢Donglecow的努力,但我终于明白了这个问题。它不是date_of_creation字段。我试图访问'文档'中的'对象',这是不可能的,因为它可以给我的是变量。 doc ['m_skill.skillarea']做了诡计。 –