【发布时间】:2014-12-24 06:01:49
【问题描述】:
我有一个 elasticsearch 文档结构,我希望有一个术语方面(或聚合),我获得独立于它们出现的字段的文档数量。
例如,以下结果显示文档和分面搜索结果:
{
"_shards": {
"failed": 0, "successful": 5, "total": 5
},
"hits": {
"hits": [
{
"_id": "003", "_index": "test", "_score": 1.0, "_type": "test",
"_source": {
"root": {
"content": [
"five",
"five",
"five"
],
"title": "four"
}
}
},
{
"_id": "002", "_index": "test", "_score": 1.0, "_type": "test",
"_source": {
"root": {
"content": "two three",
"title": "three"
}
}
},
{
"_id": "001", "_index": "test", "_score": 1.0, "_type": "test",
"_source": {
"root": {
"content": "one two",
"title": "one"
}
}
}
],
"max_score": 1.0, "total": 3
},
"facets": {
"terms": {
"_type": "terms", "missing": 0, "other": 0,
"terms": [
{
"count": 2,
"term": "two"
},
{
"count": 2,
"term": "three"
},
{
"count": 2,
"term": "one"
},
{
"count": 1,
"term": "four"
},
{
"count": 1,
"term": "five"
}
],
"total": 8
}
},
"timed_out": false,
"took": 18,
}
我们可以看到术语“一”和“三”的计数为 2(对于同一文档的每个字段一次),我希望它们计数为 1。唯一计数为 2 的术语应该是“二”。
我研究了聚合以查看它是否有帮助,但它似乎不适用于多个字段(或者我错过了一些东西)。
在“根”而不是单个字段上构建“术语”方面会很好......但这似乎也不可能。
任何想法,如何解决这个问题?
【问题讨论】:
标签: elasticsearch aggregation facets