Elasticsearch 脚本数组大小

Elasticsearch scripting array size

谁能帮我构造以下查询。当 运行 此查询时,我遇到以下错误。 ES版本为7.9.0; 在我的模型中有一个字段“repliedBy”,它是一个数组字段。它的值总是用空数组初始化。但是在某些实体上它有一个或几个对象。我需要编写一个查询来获取所有只有空数组的项目。

   GET myTable/_search
    {
      "query": {
        "bool": {
          "must": [
            {
              "script": {
                "script": {
                  "source": "doc['repliedBy'].size() == params.val",
                  "params": {
                    "val": 0
                  }
                }
              }
            },
            {
              "range": {
                "receivedDate": {
                  "gte": "2020-09-15T07:51:21.000Z",
                  "lte": "2020-12-01T07:51:21.000Z"
                }
              }
            }
          ]
        }
      }
    }

错误:

  "error" : {
    "root_cause" : [
      {
        "type" : "script_exception",
        "reason" : "runtime error",
        "script_stack" : [
          "org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:90)",
          "org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:41)",
          "doc['repliedBy'].size() == params.val",
          "    ^---- HERE"
        ],
        "script" : "doc['repliedBy'].size() == params.val",
        "lang" : "painless",
        "position" : {
          "offset" : 4,
          "start" : 0,
          "end" : 37
        }
      }
    ],

这是 bool/must_not/exists 查询组合的作业,如下所示:

{
  "query": {
    "bool": {
      "must_not": [
        {
          "exists": {
            "field": "repliedBy.id"
          }
        }
      ],
      "filter": [
        {
          "range": {
            "receivedDate": {
              "gte": "2020-09-15T07:51:21.000Z",
              "lte": "2020-12-01T07:51:21.000Z"
            }
          }
        }
      ]
    }
  }
}