弹性搜索动态聚合

时间:2014-05-23 22:21:35

标签: elasticsearch

我有一个产品类型的索引,这个产品有一些共同的属性,但依赖于类别有不同的属性(我做一个dinamyc映射)。

如何最好地映射它并在聚合之后进行聚合,而不知道如何命名该字段。

[specifications] => Array
                   (
                     [properties] => Array
                     (
                      [property1] => Array
                      (
                       [type] => string
                       [index] => not_analyzed
                      )
                      [property2] => Array
                      (
                       [type] => string
                       [index] => not_analyzed
                      ),
                      etc...
                      )
                     )

2 个答案:

答案 0 :(得分:1)

我找到了解决方案: 映射:

'attributes' => array(
                    'type' => 'nested',
                    'properties' => array(
                        'key' => array(
                            'type' => 'string',
                            'index' => 'not_analyzed',
                        ),
                        'value' => array(
                            'type' => 'string',
                            'index' => 'not_analyzed',
                        ),
                    ),
                ),

AGGS:

'attributes' => array(
                'nested' => array(
                    'path' => 'attributes',
                ),
                'aggs' => array(
                    'key' => array(
                        'terms' => array(
                            'field' => 'attributes.key',
                        ),
                        'aggs' => array(
                            'value' => array(
                                'terms' => array(
                                    'field' => 'attributes.value',
                                ),
                            ),
                        ),
                    ),
                ),
            ),

答案 1 :(得分:0)

多重匹配查询允许通配符字段。

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html#CO27-2

您可以调整一些命名约定或隔离要在对象字段(http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-object-type.html)中搜索的字段,然后使用widlcard来定位这些内部字段。

相关问题