未映射字段上的嵌套聚合

时间:2017-03-28 14:41:55

标签: elasticsearch

我试图在弹性的嵌套字段上执行脚本聚合。复杂的是我的字段根本没有包含在映射中。映射是:

{
    "my_index": {
        "my_type": {
            "properties": {
                "Fields": {
                    "type": "nested",
                    "dynamic": "false",
                    "properties": {
                        "fieldname": {
                            "type": "string",
                            "index": "not_analyzed"
                        },
                        "filtered": {
                            "type": "string",
                            "analyzer": "keyword"
                        },
                        "index": {
                            "type": "integer"
                        },
                        "policy": {
                            "type": "string",
                            "index": "not_analyzed"
                        },
                        "profile": {
                            "type": "boolean"
                        },
                        "result": {
                            "type": "integer"
                        },
                        "type": {
                            "type": "string",
                            "index": "not_analyzed"
                        },
                        "uri": {
                            "type": "string",
                            "index": "not_analyzed"
                        }
                    }
                }
            }
        }
    }
}

我正在执行的聚合查询

POST my_index/my_type/_search
{
    "size": 0,
    "aggs": {
        "fields": {
            "nested": {
                "path": "Fields"
            },
            "aggs": {
                "distinct_content": {
                    "terms": {
                        "field": "Fields.content"
                    }
                }
            }
        }
    }
}

但是我没有得到嵌套聚合的结果。我尝试使用scripted_metric聚合,但我似乎仍然无法访问内容字段。是否可以访问根本没有映射的字段?

1 个答案:

答案 0 :(得分:0)

由于您禁用了动态映射,因此无法通过搜索或聚合访问此字段。请参阅此documentation site的底部注释(它是一般映射注释,但它也适用于嵌套对象)。

尽管如此,您可以使用PUT mapping API然后重新索引来轻松扩展映射,并且应该可以访问它。

相关问题