嵌套文档中文档计数的弹性搜索过滤器 [英] elastic search filter by documents count in nested document
本文介绍了嵌套文档中文档计数的弹性搜索过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在弹性搜索中使用了这种模式.
I have this schema in elastic search.
79[
'ID' : '1233',
Geomtries:[{
'doc1' : 'F1',
'doc2' : 'F2'
},
(optional for some of the documents)
{
'doc2' : 'F1',
'doc3' : 'F2'
}]
]
几何是一个嵌套元素.我想获取所有在Geometries中具有一个对象的文档.
the Geometries is a nested element. I want to get all of the documents that have one object inside Geometries.
到目前为止已经尝试过:
Tried so far :
"script" : {"script" : "if (Geomtries.size < 2) return true"}
但我有例外:没有此类属性GEOMTRIES
But i get exceptions : no such property GEOMTRIES
推荐答案
如果您在映射中将字段的类型设置为 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
.
这篇关于嵌套文档中文档计数的弹性搜索过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文