弹性搜索查询字符串异常

时间:2018-02-06 13:38:33

标签: elasticsearch

我是弹性搜索的新手,我编写了一个查询来过滤允许与用户聊天的用户。我写下面的查询

   {
    "_source": [
      "id","username","is_live", 
      "full_name","message_privacy","followings"
    ],
    "sort": [
      {
        "username.raw": {
          "order": "desc"
        }
      }
    ], 
    "query": {
      "bool": {
        "must": [
          {
            "terms": {
              "message_privacy": [0,1]
            }
          },
          {"prefix": {"username": {"value": ""}}},

           {
            "script": {
              "script": {
                "source": "if( doc.message_privacy.value == 1){ return true;} List x = new ArrayList(doc['followings.key'].values);return x.contains(params.keyword) && doc.message_privacy.value ==0 ;",
                "lang": "painless",
                "params": {
                  "keyword": 19712
                }
              }
            }
          }
        ]
      }
    }
  }

异常

    {
  "error": {
    "root_cause": [
      {
        "type": "script_exception",
        "reason": "runtime error",
        "script_stack": [
          "org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:77)",
          "org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:36)",
          "x = new ArrayList(doc['followings.key'].values);",
          "                      ^---- HERE"
        ],
        "script": "if( doc.message_privacy.value == 1){ return true;} List x = new ArrayList(doc['followings.key'].values);return x.contains(params.keyword) && doc.message_privacy.value ==0 ;",
        "lang": "painless"
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "users",
        "node": "tK_Gh0amTeSOiOYLFvn04w",
        "reason": {
          "type": "script_exception",
          "reason": "runtime error",
          "script_stack": [
            "org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:77)",
            "org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:36)",
            "x = new ArrayList(doc['followings.key'].values);",
            "                      ^---- HERE"
          ],
          "script": "if( doc.message_privacy.value == 1){ return true;} List x = new ArrayList(doc['followings.key'].values);return x.contains(params.keyword) && doc.message_privacy.value ==0 ;",
          "lang": "painless",
          "caused_by": {
            "type": "illegal_argument_exception",
            "reason": "No field found for [followings.key] in mapping with types [user]"
          }
        }
      }
    ]
  },
  "status": 500
}

如果我使用params._source ['以下']那么它的工作正常但我想用性能来完成这个。我不知道我的代码在哪里犯了错误。我也从以下链接获得帮助但没有成功Elasticsearch - Script filter on array

0 个答案:

没有答案