elasticsearch,aggregation,Json,Search,elasticsearch,Aggregation" /> elasticsearch,aggregation,Json,Search,elasticsearch,Aggregation" />

Json 多重聚合elasticsearch中START_对象的未知密钥

Json 多重聚合elasticsearch中START_对象的未知密钥,json,search,elasticsearch,aggregation,Json,Search,elasticsearch,Aggregation,我正在尝试构建一个查询,允许我在单个查询上进行多个聚合(在同一级别上,而不是子聚合)。这是我发出的请求: { "index": "index20", "type": "arret", "body": { "size": 0, "query": { "bool": { "must": [ { "mul

我正在尝试构建一个查询,允许我在单个查询上进行多个聚合(在同一级别上,而不是子聚合)。这是我发出的请求:

{
    "index": "index20",
    "type": "arret",
    "body": {
        "size": 0,
        "query": {
            "bool": {
                "must": [
                    {
                        "multi_match": {
                            "query": "anim fore",
                            "analyzer": "query_analyzer",
                            "type": "cross_fields",
                            "fields": [
                                "doc_id"
                            ],
                            "operator": "and"
                        }
                    }
                ]
            }
        },
        "aggs": {
            "anim_fore": {
                "terms": {
                    "field": "suggest_keywords.autocomplete",
                    "order": {
                        "_count": "desc"
                    },
                    "include": {
                        "pattern": "anim.*fore.*"
                    }
                }
            },
            "fore": {
                "terms": {
                    "field": "suggest_keywords.autocomplete",
                    "order": {
                        "_count": "desc"
                    },
                    "include": {
                        "pattern": "fore.*"
                    }
                }
            }
        }
    }
}
但是,我在执行此查询时遇到以下错误:

Error: [parsing_exception] Unknown key for a START_OBJECT in [fore]., with { line=1 & col=1351 }
我一直试图以多种形式更改此查询以使其正常工作,但最终总是出现此错误。这对我来说真的很奇怪,因为此查询似乎与此处指定的格式兼容:


也许术语聚合有一些特殊的地方,但我还没有整理出来。

doc\u id
之后有尾随的逗号,在关闭
must
的数组标记之后,您的查询应该是这样的

"must": [
    {
        "multi_match": {
            "query": "anim fore",
            "analyzer": "query_analyzer",
            "type": "cross_fields",
            "fields": [
                "doc_id" // You have trailing comma here
            ],
            "operator": "and"
        }
    }
] // And here

错误出现在您的
包含设置中,它应该只是字符串

    "aggs": {
        "anim_fore": {
            "terms": {
                "field": "suggest_keywords.autocomplete",
                "order": {
                    "_count": "desc"
                },
                "include": "anim.*fore.*"              <--- here
            }
        },
        "fore": {
            "terms": {
                "field": "suggest_keywords.autocomplete",
                "order": {
                    "_count": "desc"
                },
                "include": "fore.*"                    <--- and here
            }
        }
    }
“aggs”:{
“动画片”:{
“条款”:{
“字段”:“建议关键字。自动完成”,
“命令”:{
“计数”:“描述”
},

“包括”:“动画。*fore.*”我只是在我的帖子中修改了json以便缩短。这些尾随逗号在原始json中不存在。include不应该有模式属性,它应该是stringIt似乎与include子句有关。我一秒钟前才意识到。你知道为什么include.pattern语法在只有一个聚合时有效,但在有多个聚合时无效?奇怪的是,我从未在任何地方见过
include.pattern