官术网_书友最值得收藏!

Aggregating your results

Next, when I search for Lenovo, I would like to see different product types associated with it. This is more like making a report out of the results, but then, as this makes your data more explorable and easy to understand, it's safe to see this as enhancing search capabilities.

Hence, whenever I search for something, I want to see the following reports on my query results or rather, an aggregate of my results in the following information:

  • Different types of productType
  • The number of products in various predefined price ranges
  • The number of documents per year based on manufacturing dates

For this, we need to build different aggregations to capture these reports.

Note

It's very important to understand that the score of aggregation is the query. This means that the aggregations would only be done on those documents that match the query.

The format in which we should provide aggregations is as follows:

{
    "query" : { ….},
    "aggregations" : { 
        "aggregationNameA" : { 
            "aggregationType" : { <Aggregation type specific information> },
        }
    },
    "aggregationNameB" : { 
        "aggregationType" : { <Aggregation type specific information> },
        }
    },
    { …. }
}

Once we fire a search request with this JSON, we can retrieve our results in the following format:

{
    "took" : 21 ,
     ….
}
Note

We identify the results of the inpidual aggregation request using the aggregation name we gave in the query.

Terms aggregation

Terms aggregation is usually done on string field types, which means that this is very handy to retrieve statistics on terms. Like in our case, the number of different unique values for the productType and the number of documents in which each terms are occurring.

主站蜘蛛池模板: 汉源县| 禹州市| 开化县| 兴海县| 大余县| 确山县| 澄江县| 林周县| 新邵县| 洛宁县| 获嘉县| 民乐县| 卓资县| 股票| 秀山| 彭阳县| 惠水县| 武胜县| 昆山市| 二手房| 南岸区| 许昌市| 东乌珠穆沁旗| 屏边| 儋州市| 嫩江县| 陆良县| 根河市| 沈丘县| 巴楚县| 富裕县| 平塘县| 河津市| 峡江县| 咸宁市| 崇信县| 本溪| 肇源县| 永胜县| 尼勒克县| 金湖县|