gpt4 book ai didi

elasticsearch - 如何在Elasticsearch中过滤嵌套文档?

转载 作者:行者123 更新时间:2023-12-03 01:04:01 25 4
gpt4 key购买 nike

我有一些看起来像的文件

  {
"_id": "56161cb3cbdad2e3b437fdc3",
"_type": "Comunity",
"name": "public",
"data": [
{
"title": "sonder",
"creationDate": "2015-08-22T03:43:28 -03:00",
"quantity": 0
},
{
"title": "vule",
"creationDate": "2014-05-17T12:35:01 -03:00",
"quantity": 0
},
{
"title": "omer",
"creationDate": "2015-01-31T04:54:19 -02:00",
"quantity": 3
},
{
"title": "sonder",
"creationDate": "2014-05-22T05:09:36 -03:00",
"quantity": 3
}
]
}

映射:
      comunityDocument": {
"_source": {
"includes": [
"meta.*"
]
},
"properties": {
"doc": {
"dynamic": "false",
"properties": {
"data": {
"type": "nested",
"include_in_parent": true,
"properties": {
"title": {
"type": "string"
},
"creationDate": {
"type": "date",
"format": "dateOptionalTime"
},
"quantity": {
"type": "integer"
}
}
},
"name": {
"type": "string",
"index": "not_analyzed"
}
}
},
"meta": {
"include_in_all": false,
"properties": {
"expiration": {
"type": "long",
"include_in_all": false
},
"flags": {
"type": "long",
"include_in_all": false
},
"id": {
"type": "string",
"include_in_all": false
},
"rev": {
"type": "string",
"include_in_all": false
}
}
}
}
}

而我的查询
{
"size": 0,
"aggs": {
"filterAgg": {
"filter": {
"nested": {
"path": "comunityDocument.doc.data",
"filter": {
"terms": {
"comunityDocument.doc.data.quantity": [
0
]
}
}
}
}
}
}
}

结果,我必须对数量等于0的所有“数据”文档进行计数,但我没有。嵌套聚合起作用但奇怪的是嵌套过滤器无效。

最佳答案

如果comunityDocument是类型,则正确的查询应为

{
"size": 0,
"aggs": {
"filterAgg": {
"filter": {
"nested": {
"path": "doc.data",
"filter": {
"terms": {
"doc.data.quantity": [
0
]
}
}
}
}
}
}
}

关于elasticsearch - 如何在Elasticsearch中过滤嵌套文档?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33282535/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com