我希望计算一些带索引的产品数据的值计数聚合,但我似乎在ValueCountAgg构造函数中获得了错误的一些参数。
这样的索引数据的示例如下-:
{
"_index": "test-index",
"_type": "product_product",
"_id": "1",
"_score": 1,
"_source": {
"code": "SomeProductCode1",
"list_price": 10,
"description": null,
"displayed_on_eshop": "true",
"active": "true",
"tree_nodes": [],
"id": 1,
"category": {},
"name": "This is Product",
"price_lists": [
{
"price": 10,
"id": 1
},
{
"price": 10,
"id": 2
}
],
"attributes": {
"color": "blue",
"attrib": "something",
"size": "L"
},
"type": "goods"
}
}我按照下面的-计算聚合:
for attribute in filterable_attributes:
count = ValueCountAgg(
name='count_'+attribute, field='attributes.'+attribute
)
query.agg.add(count)其中query是包装在~pyes.query.Search对象中的~pyes.query.Query对象。filterable_attributes是属性名称的列表,例如颜色和大小。
我也尝试过设置field=attribute,但似乎没有什么不同。我在执行搜索时获得的结果集的aggs属性-如下:
{'count_size': {'value': 0}, 'count_color': {'value': 0}}其中,size和color在attributes字典中进行索引,如上所示。这些显然是错误的结果,我认为这是因为我没有正确设置field。
我哪里错了?
发布于 2014-12-24 18:26:10
我发现我错在哪里了。
根据Scoping Aggregations的说法,聚合的作用域默认情况下与其查询相关联。我的查询返回零个结果,因此我必须修改搜索短语。
在那之后,我得到了所需的结果,聚合出来的结果是正确的。
{'count_size': {'value': 3}, 'count_color': {'value': 3}}https://stackoverflow.com/questions/27634579
复制相似问题