2016-01-21 25 views
0

我與彈性搜索一個新手,並在寫我面臨的解析異常說script_score「預期字段名,但得到[START_ARRAY]」如何在script_score中編寫腳本(內聯),其中包括一些自定義邏輯,如果對doc []元素有條件?

這裏是映射:

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文檔)

回答

0

它看起來像您錯誤地將size選項放在您的查詢中。在您的示例中,您已將其添加爲function_score查詢旁邊的字段。相反,它屬於根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 
} 

看一看爲request body search的文檔。

相關問題