X
X
xphoenyx2016-09-24 20:38:19
elasticsearch
xphoenyx, 2016-09-24 20:38:19

How to select documents for a specific category with aggregation?

There is a portal for exhibiting auctions. Auction data (documents) is stored in the elasticsearch index. Each auction belongs to one category, which in turn has parent categories. IDs of child and parent categories are stored in a separate field of the auction document as a nested structure:

{
    ...
    'categories': {
         'level1': 3 // <- Категория аукциона (пример: видеокарты)
         'level2': 34 // <- Родительская категория (пример: компоненты)
         'level3': 152 // <- Родительская категория (пример: компьютеры)
    }
    ...
}

I have two tasks: to select documents with a specific category from the index, and in doing so, perform an aggregation that will count the number of auctions in each category affected by the query.
Question: what should JSON look like with a request that fulfills these conditions?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Cheremisin, 2016-09-25
@leahch

If your category number is unique, then why did you split them into several properties? Wouldn't it be easier to just make the 'level':[3,34,152]. Then the aggregation will be in one request!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question