itemsapi / dashboard

Interactive user interface for your data in ItemsAPI
MIT License
21 stars 18 forks source link

Add multilevel structure example #8

Open pilot opened 8 years ago

pilot commented 8 years ago

simple and ofter to use categories structure like:

cigolpl commented 8 years ago

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

Or mapping example with object fields ?

pilot commented 8 years ago

image

this is usual case

cigolpl commented 8 years ago

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 ?

pilot commented 8 years ago

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"
cigolpl commented 8 years ago

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

pilot commented 8 years ago

yeah this is looks like :+1:

cigolpl commented 8 years ago

@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 commented 8 years ago

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']
    ]},
  }
}
pilot commented 8 years ago

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