elasticsearch,Parsing,elasticsearch" /> elasticsearch,Parsing,elasticsearch" />

Parsing 如何在script_score中编写脚本(内联),包括一些自定义逻辑和doc[]元素上的if条件?

Parsing 如何在script_score中编写脚本(内联),包括一些自定义逻辑和doc[]元素上的if条件?,parsing,elasticsearch,Parsing,elasticsearch,我是一个弹性搜索的新手,在编写脚本时,我遇到了一个解析异常:“预期的字段名,但得到了[START\u ARRAY]” 以下是映射: PUT toadb { "mappings":{ "keywords":{ "properties":{ "Name":{"type":"string","analyzer": "simple"}, "Type":{"type":"string","index": "not_anal

我是一个弹性搜索的新手,在编写脚本时,我遇到了一个解析异常:“预期的字段名,但得到了[START\u ARRAY]”

以下是映射:

PUT toadb
{
   "mappings":{
      "keywords":{
         "properties":{
            "Name":{"type":"string","analyzer": "simple"},
            "Type":{"type":"string","index": "not_analyzed"},
            "Id":{"type":"string","index": "not_analyzed"},
            "Boosting Field":{"type" : "integer", "store" : "yes"}
            }
        },
      "businesses":{
          "properties": {
          "Name":{"type":"string","analyzer": "simple"},
          "Type":{"type":"string","index": "not_analyzed"},
          "Id":{"type":"string","index": "not_analyzed"},
          "Business_seq":{"type":"string","index": "not_analyzed"},
          "Status":{"type":"string","index": "not_analyzed"},
          "System_rating":{"type" : "integer", "store" : "yes"},
          "System_rating_weight":{"type" : "integer", "store" : "yes"},
          "Position":{ "type":"geo_point","lat_lon": true},
          "Display Pic":{"type": "string","index": "not_analyzed"},
          "Boosting Field":{"type" : "integer", "store" : "yes"}
            }
        }
    }
}
以下是我正在尝试执行的查询:

 GET /toadb/_search
        {
            "query":{
            "function_score" : {
                 "query" : {
                       "multi_match" : {
                                "query":    "Restaurant", 
                                "fields": [ "Name"],"fuzziness":1 
                                }},

                       "script_score":
                        {
                           "script":"if(doc['Status'] && doc['Status']=='A'){ _score+ (doc['Boosting Field'].value);}"
                        }
            },
            "size":10
         }
}

请提供示例(如有)(已参考elasticsearch文档)

看起来您在查询中错误地放置了
大小
选项。在您的示例中,您已将其添加为
函数\u分数
查询旁边的字段。相反,它属于根
query
对象的同级

试试这个:

GET /toadb/_search
{
  "query": {
    "function_score": {
      "query": {
        "multi_match": {
          "query": "Restaurant",
          "fields": [
            "Name"
          ],
          "fuzziness": 1
        }
      },
      "script_score": {
        "script": "if(doc['Status'] && doc['Status']=='A'){ _score+ (doc['Boosting Field'].value);}"
      }
    }
  },
  "size": 10
}
请查看有关的文档