Elastic search aggregations of multilevel navigation, excluding granules by groups

I am new to ES and trying to implement faceted navigation in the same way as most major e-commerce stores.

Part of my product mapping is as follows:

'name' => [
    'type' => 'string',
    'analyzer' => 'english_analyzer',
],
'range' => [
    'type' => 'string',
    'analyzer' => 'english_analyzer',
],
'filters' => [
    'type' => 'nested',
    'properties' => [
        'name' => [
            'type' => 'string',
            'index' => 'not_analyzed',
        ],
        'values' => [
            'type' => 'object',
            'properties' => [
                'name' => [
                    'type' => 'string',
                    'index' => 'not_analyzed',
                ]
            ]
        ]
    ]
],

As you can see, I save the facets in the "filters" as a nested object.

In my search query, I can add this aggregation to my query:

'aggs' => [
    'facets' => [
        'nested' => ['path' => 'filters'],
        'aggs' => [
            'filters' => [
                'terms' => [
                    'field' => 'filters.name', //facet group name
                    'size' => 0
                ],
                'aggs' => [
                    'id' => [
                        'terms' => [
                            'field' => 'filters.id' //facet group ID
                        ]
                    ],
                    'values' => [
                        'terms' => [
                            'field' => 'filters.values.name', //facet name
                            'size' => 0
                        ],
                        'aggs' => [
                            'id' => [
                                'terms' => [
                                    'field' => 'filters.values.id' //facet id
                                ]
                            ]
                        ]
                    ]
                ]
            ]
        ]
    ]
]

This gives me a good list of facets that can be used in my navigation. I can apply the selected faces to the results of my document in two ways: using the "filter by mail" or "filtered request"

post , . , , .

- - 2. , , , .

:

:

  • (1)
  • (2)
  • (3)

Brands:

  • Audi (1)
  • Ford (2)
  • BMW (3)

- , , .

: ElasticSearch:

, , ( ) . , (https://www.elastic.co/guide/en/elasticsearch/guide/current/_filter_bucket.html) . bool, , , , .

, , / , , bool, . , , , , !

, , , , . ?

, , .

+4

Source: https://habr.com/ru/post/1624885/


All Articles