大家好。尝试使用弹性搜索收集数据时,我有一个非常奇怪的问题。我通过语言,扩展和模块存储来自SVN行更改的数据。对于本节,我使用术语进行搜索。 这是一个例子: 数据以以下形式存储:
_source: {
files: 3,
revision_change: {
add: {
detail: {
total: 76124,
source: [
{
lines: 76124,
key: "human"
}
],
extension: [
{
lines: 18,
key: "without_extension"
},
{
lines: 5,
key: "py"
},
{
lines: 76101,
key: "sql"
}
],
language: [
{
lines: 5,
key: "Python"
},
{
lines: 18,
key: "Undefined"
},
{
lines: 76101,
key: "SQL"
}
],
module: [
]
}
},
remove: {
detail: {
total: 74573,
source: [
{
lines: 74573,
key: "human"
}
],
extension: [
{
lines: 13,
key: "without_extension"
},
{
lines: 4,
key: "py"
},
{
lines: 74556,
key: "sql"
}
],
language: [
{
lines: 4,
key: "Python"
},
{
lines: 13,
key: "Undefined"
},
{
lines: 74556,
key: "SQL"
}
],
module: [
]
}
}
这是1次修订。现在,我使用查询按天分组,所以我希望按天进行适当的修订。但奇怪的是:总数被正确添加,但是通过语言或扩展,总和非常糟糕。
{
took: 4,
timed_out: false,
_shards: {
total: 5,
successful: 5,
failed: 0
},
hits: {
total: 21,
max_score: 0,
hits: [
]
},
aggregations: {
articles_over_time: {
buckets: [
{
key_as_string: "2015-01-12T00:00:00.000Z",
key: 1421020800000,
doc_count: 2,
add_total: {
value: 1676461
},
add_language: {
buckets: [
{
key: "python",
doc_count: 2,
lines: {
value: 1676461
}
},
{
key: "sql",
doc_count: 2,
lines: {
value: 1676461
}
},
{
key: "undefined",
doc_count: 1,
lines: {
value: 76124
}
}
]
}
}
正如您所看到的,Python行的总和等于SQL行,但这实际上是所有行的总和。 这是我使用的查询:
http://localhost:9200/test5/svn/_search?pretty&source={
"query": {
"bool": {
"must": [
{
"term": {
"project_id": "2"
}
}
]
}
},
"size": 0,
"aggs": {
"articles_over_time": {
"date_histogram": {
"field": "date",
"interval": "day"
},
"aggs": {
"add_language": {
"terms": {
"field": "revision_change.add.detail.language.key"
},
"aggs":{
"lines": {
"sum":{
"field": "revision_change.add.detail.language.lines"
}
}
}
},
"add_total":{
"sum":{
"field": "revision_change.add.detail.total"
}
}
}
}
}
}
有人面对这个问题吗?谢谢你的帮助。