且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

嵌套文档中文档计数的弹性搜索过滤器

更新时间:2023-02-08 20:02:50

如果您在映射中将字段的类型设置为 nested ,则通常使用 doc [fieldkey] .values.size()似乎无效.我发现以下脚本可以正常工作:

If you have the field as type nested in the mapping, the typical doc[fieldkey].values.size() approached does not seem to work. I found the following script to work:

{
  "from" : 0,
  "size" : <SIZE>,
  "query" : {
    "filtered" : {
      "filter" : {
        "script" : {
          "script" : "_source.containsKey('Geomtries') && _source['Geomtries'].size() == 1"
        }
      }
    }
  }
}

注意:您必须使用 _source 而不是 doc .

NB: You must use _source instead of doc.