如果我们在elasticsearch中有以下文件:
[
{'name': 'John', 'time': '2013-01-01 12:01:00'},
{'name': 'John', 'time': '2013-01-01 12:02:00'},
{'name': 'John', 'time': '2013-01-01 12:03:00'},
{'name': 'John', 'time': '2013-01-01 12:04:00'},
{'name': 'Harry', 'time': '2013-01-01 12:05:00'},
{'name': 'Fred', 'time': '2013-01-01 12:06:00'},
{'name': 'Fred', 'time': '2013-01-01 12:07:00'}
]
我们面对'名称'字段,我们会得到这样的结果:
"facets": {
"count_per_name": {
"_type": "terms",
"missing": 0,
"total": 7,
"other": 0,
"terms": [
{
"term": "John",
"count": 4
},
{
"term": "Fred",
"count": 2
},
{
"term": "Harry",
"count": 1
}
]
}
}
我的问题是:是否可以在elasticsearch中执行分面查询,其中name
“John”的文档计为“half”文档?这将导致约翰的数量从4下降到2,但弗雷德和哈利保持不变:
"facets": {
"count_per_name": {
"_type": "terms",
"missing": 0,
"total": 5,
"other": 0,
"terms": [
{
"term": "John",
"count": 2
},
{
"term": "Fred",
"count": 2
},
{
"term": "Harry",
"count": 1
}
]
}
}
答案 0 :(得分:0)
并指定value_script,其中John为John返回0.5,其他人返回1,并使用SUM facet结果进行操作。虽然这种方法受性能影响