dashboard icon indicating copy to clipboard operation
dashboard copied to clipboard

Add multilevel structure example

Open pilot opened this issue 10 years ago • 9 comments

simple and ofter to use categories structure like:

  • category
    • sub category
  • category
  • category
    • sub category
    • sub category

pilot avatar Dec 04 '15 00:12 pilot

Do you mean object structure for showing in the table: selection_376

Or mapping example with object fields ?

cigolpl avatar Dec 04 '15 14:12 cigolpl

image

this is usual case

pilot avatar Dec 04 '15 14:12 pilot

Thanks for example. I don't think it will work with the current API version but it is definitely good use case for some requirements (i.e. ecommerce !?)

I am thinking about the implementation and wondering how to store data that elasticsearch will be aware that sub1 and sub2 are 'children' of category ?

parent field - https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-parent-field.html ?

cigolpl avatar Dec 04 '15 14:12 cigolpl

not only for ecommerce, but for any catalog contain system, like a sales aggregation page

there is example of mapping for nested field from real project

variants:
                            type: "nested"
                            properties:
                                id:
                                    type: "integer"
                                status:
                                    type: "boolean"
                                prices:
                                    type: "nested"
                                    properties:
                                        value:
                                            type: "integer"
                                        oldValue:
                                            type: "integer"
                                        currencyCode:
                                            type: "string"
                                options:
                                    type: "nested"
                                    properties:
                                        id:
                                            type: "integer"
                                        value:
                                            type: "string"
                                            index: not_analyzed
                                        minSize:
                                            type: "integer"
                                        maxSize:
                                            type: "integer"

pilot avatar Dec 04 '15 14:12 pilot

It is not easy for implementation but it would be great feature. It seems there is a solution http://stackoverflow.com/a/26314598/659682 ;)

cigolpl avatar Dec 04 '15 17:12 cigolpl

yeah this is looks like :+1:

pilot avatar Dec 04 '15 22:12 pilot

@pilot as I said this is great feature and even I would use it but it will take more time because I don't know yet how to make it simple and don't affect too much current functionality (import / export, / schema / response / elasticsearch mapping converting).

How would you like to provide data to ItemsAPI to achieve multilevel structure in API response ?

My idea is to add new aggregations type which override current terms aggregation and it will take additional field from item i.e. paths

var paths = [
  'category1': ['sub-category1', 'sub-category2'],
  'category2': ['sub-category1', 'sub-category3'],
  'category3': ['sub-category2', 'sub-category3'],
  'sub-category2': ['sub-sub-category1']
]

Current terms aggregation looks like:

{
  "aggregations": {
    "actors_terms": {"type": "terms", "field": "actors", "size": 10, "title": "Actors"},
  }
}

and the another new one aggregation could look like:

{
  "aggregations": {
    "actors_terms": {"type": "recursive_terms", "field": "category", "size": 10, "title": "Categories", "paths": "paths"},
  }
}

It would generate multilevel filters out of the box like in your picture.

Do you think does it make sense ?

cigolpl avatar Dec 12 '15 10:12 cigolpl

I am sorry, configuration could look like this without additional field:

{
  "aggregations": {
    "actors_terms": {"type": "recursive_terms", "field": "category", "size": 10, "title": "Categories", "paths": [
      'category1': ['sub-category1', 'sub-category2'],
      'category2': ['sub-category1', 'sub-category3'],
      'category3': ['sub-category2', 'sub-category3'],
      'sub-category2': ['sub-sub-category1']
    ]},
  }
}

cigolpl avatar Dec 12 '15 12:12 cigolpl

yes, to clarify above aggregations will valid only for nested type mapping?

pilot avatar Dec 12 '15 22:12 pilot