0

我希望计算一些索引产品数据的值计数聚合,但我似乎在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.Query~pyes.query.Searchfilterable_attributes

我也尝试过设置field=attribute,但似乎没有什么区别。我在进行搜索时获得的结果集具有以下aggs属性-:

{'count_size': {'value': 0}, 'count_color': {'value': 0}}

wheresizecolorattributes字典中被索引,如上所示。这些显然是错误的结果,我认为是因为我没有field正确设置。

我哪里错了?

4

1 回答 1

1

我发现我哪里出错了。

根据Scoping Aggregations,聚合的范围默认与其查询相关联。我的查询返回零结果,我不得不修改搜索短语。

在那之后我得到了所需的结果,并且聚合出来了。

{'count_size': {'value': 3}, 'count_color': {'value': 3}}
于 2014-12-24T10:26:09.717 回答