Elasticsearch脚本查询无效

时间:2017-12-29 10:38:43

标签: javascript elasticsearch

我正在使用脚本排除搜索结果,但它无法按预期工作。我检查索引中的所有数据,selluserid的值为null和0。

{
  "script": {
            "script": {
              "inline": "(doc['isshoper'].value == 0) || params.arrShopUser.get(doc['selluserid'].value.toString())",
              "params": {
                "arrShopUser": {
                  "95794": true,
                  "214214": true,
                  "329221": true,
                  "8888": true,
                  "373502": true,
                  "309235": true,
                  "383247": true,
                  "383252": true,
                  "9999": true,
                  "637312": true,
                  "642158": true,
                  "445055": true,
                  "444214": true,
                  "821435": true,
                  "1111": true,
                  "2222": true,
                  "6666": true,
                  "7777": true,
                  "4444": true,
                  "666": true,
                  "777": true,
                  "222": true,
                  "333": true,
                  "555": true,
                  "888": true,
                  "66633": true,
                  "1991944": true,
                  "1991949": true,
                  "1991941": true,
                  "1992000": true,
                  "1992019": true,
                  "1992023": true,
                  "1992046": true,
                  "1992068": true,
                  "1992006": true,
                  "1992055": true
                }
              }
            }
          }
        }

错误消息

{
  "error": {
    "root_cause": [
      {
        "type": "script_exception",
        "reason": "runtime error",
        "script_stack": [
          "(doc['isshoper'].value == 0) || params.arrShopUser.get(doc['selluserid'].value.toString())",
          "                                                                              ^---- HERE"
        ],
        "script": "(doc['isshoper'].value == 0) || params.arrShopUser.get(doc['selluserid'].value.toString())",
        "lang": "painless"
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "tsy_trade",
        "node": "1MbSaY-RR6GPgo_AI-g8GA",
        "reason": {
          "type": "script_exception",
          "reason": "runtime error",
          "script_stack": [
            "(doc['isshoper'].value == 0) || params.arrShopUser.get(doc['selluserid'].value.toString())",
            "                                                                              ^---- HERE"
          ],
          "script": "(doc['isshoper'].value == 0) || params.arrShopUser.get(doc['selluserid'].value.toString())",
          "lang": "painless",
          "caused_by": {
            "type": "null_pointer_exception",
            "reason": null
          }
        }
      }
    ]
  },
  "status": 500
}

1 个答案:

答案 0 :(得分:0)

请尝试使用此脚本:

(doc['isshoper'].value == 0) || (doc['isshoper'].value == null) || params.arrShopUser.get(doc['selluserid'].value.toString())