【发布时间】:2015-08-20 22:03:01
【问题描述】:
亚马逊索引中的映射如下所示。 书中嵌套了具有多字段“别名”的作者。 “alias”和“alias.raw”应该是作者中的有效字段。
{
mappings: {
book: {
properties: {
title: {
type: "string",
fields: {
raw: {type: "string", index: "not_analyzed"}
}
},
authors: {
type: "nested",
properties: {
alias: {
type: "string",
fields: {
raw : {
type: "string",
index: "not_analyzed"
}
}
},
alias_raw: {
type: "string",
index: "not_analyzed"
}
}
}
}
}
}
}
样本数据:
{索引:{_id:“1”,_type:“书”}} {标题:“傻瓜真棒”,页数:“100”,作者:[{firstName:“Apollo”,lastName:“Cabrera”,别名:“Mister Awesome”,alias_raw:“Mister Awesome”},{firstName: "Mark", lastName:"Twain", 别名: "Julius Caesar", alias_raw: "Julius Caesar"}]}
{索引:{_id:“2”,_type:“书”}} {title:“了解女性”,页数:“100000”,作者:[{firstName:“Megyn”,lastName:“Kelly”,别名:“Wonder Woman”,alias_raw:“Wonder Woman”},{firstName:“Donald ", lastName:"特朗普", 别名:"独行侠", alias_raw:"独行侠"}]}
{索引:{_id:“3”,_type:“书”}} {title:“Snap Chat”,页数:“30”,作者:[{firstName:“Hilary”,lastName:“Clinton”,别名:“Code Zero”,alias_raw:“Code Zero”},{firstName:“Harry ", lastName:"Houdini", 别名: "Abra Cadabra", alias_raw: "Abra Cadabra"}]}
我的聚合查询如下所示...
{
query: {
match_all: {}
},
aggs: {
authors: {
nested: {
path: "authors"
},
aggs: {
aliases: {
terms: {
field: "alias.raw"
}
}
}
}
}
}
当我执行聚合查询时,我根本没有聚合。如果我使用“alias_raw”(这是我添加的另一个单独字段),我会得到预期的完整别名......
"aggregations" : {
"authors" : {
"doc_count" : 6,
"aliases" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [ {
"key" : "Abra Cadabra",
"doc_count" : 1
}, {
"key" : "Code Zero",
"doc_count" : 1
}, {
"key" : "Julius Caesar",
"doc_count" : 1
}, {
"key" : "Lone Ranger",
"doc_count" : 1
}, {
"key" : "Mister Awesome",
"doc_count" : 1
}, {
"key" : "Wonder Woman",
"doc_count" : 1
} ]
}
}
}
还有其他方法可以在“alias.raw”中聚合多字段吗?如果我只使用“alias”,我会得到解析、标记、分析的小写字段.我想要未分析的原始别名。我真的认为我不需要也不想要多余的“alias_raw”字段。
提前致谢:)
【问题讨论】:
标签: elasticsearch nested field aggregation