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

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.

主站蜘蛛池模板: 广德县| 夹江县| 新津县| 景宁| 临城县| 石嘴山市| 庄浪县| 儋州市| 遂川县| 庆元县| 双城市| 马关县| 获嘉县| 崇明县| 大渡口区| 永新县| 饶阳县| 博爱县| 武定县| 黎川县| 工布江达县| 万山特区| 沙洋县| 化隆| 珠海市| 青海省| 郎溪县| 南乐县| 鹤峰县| 信丰县| 黄山市| 馆陶县| 同江市| 抚松县| 交城县| 连云港市| 社旗县| 鹤岗市| 上思县| 乌鲁木齐县| 孟连|