我有一个ES索引,嵌套数据Map如下所示
"mappings": {
"voertuig": {
"properties": {
"vestiging": {
"properties": {
"name_dtc": {
"type": "string",
"fields": {
"raw": {
"index": "not_analyzed",
"type": "string"
}
}
},
},
"type": "nested"
},
"accessoires": {
"properties": {
"name": {
"type": "string",
"fields": {
"raw": {
"index": "not_analyzed",
"type": "string"
}
}
}
},
"type": "nested"
}
}
}
}
我想创建一个查询,对两个(原始)值进行过滤。我可以创建一个过滤器,过滤这些值之一,如下所示:
{
"body": {
"post_filter": {
"nested": {
"filter": {
"bool": {
"must": [
{
"term": {
"vestiging.name_dtc.raw": "Location X"
}
}
]
}
},
"path": "vestiging"
}
},
"query": {
"match_all": { }
}
},
"index": "ocm",
"type": "voertuig"
}
然而,我需要的是这样的东西:
{
"body": {
"post_filter": {
"nested": [
{
"filter": {
"bool": {
"must": [
{
"term": {
"accessoires.name.raw": "Climate Control"
}
}
]
}
},
"path": "opties"
},
{
"filter": {
"bool": {
"must": [
{
"term": {
"vestiging.name_dtc.raw": "Location X"
}
}
]
}
},
"path": "vestiging"
}
]
},
"query": {
"filtered": {
"filter": {
"term": {
"key": "33e75ff09dd6"
}
},
"query": []
}
}
},
"index": "ocm",
"type": "voertuig"
}
第一个查询工作,第二个查询引发错误:
nested:QueryParsingException[[ocm] [nested] filter不支持[null]];
如何创建一个匹配多个路径中的字段的过滤器?
1条答案
按热度按时间lnxxn5zx1#
这个怎么样:
我认为您遇到的问题是由于不正确使用嵌套过滤器的结果,尽管从异常消息中获得确切的问题有点困难。本质上,如果你想合并两个嵌套的过滤器,你将不得不使用
bool
或and
过滤器对它们进行分组。我已经减少了查询相当多的一个较小的职位的缘故。我没有
post_filter
,因为你的例子中没有任何聚合。我把内部的bool过滤器替换成了他们拥有的单个术语过滤器,并在附加的键(term
)过滤器上标记。但是您可以继续使用您的查询结构,并根据需要扩展它,主要修复解决如何将两个嵌套过滤器放在一起。