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

  • Elasticsearch Blueprints
  • Vineeth Mohan
  • 281字
  • 2021-07-16 13:39:33

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.

主站蜘蛛池模板: 深圳市| 合作市| 都安| 汕尾市| 阿城市| 丹东市| 静乐县| 北流市| 松江区| 苏尼特左旗| 安宁市| 汶上县| 镇雄县| 建昌县| 尼玛县| 南安市| 靖边县| 新竹县| 冀州市| 麻城市| 闵行区| 来安县| 修武县| 商都县| 民勤县| 商都县| 南康市| 合肥市| 磴口县| 高要市| 阳信县| 肇东市| 澄城县| 泾川县| 赤城县| 昆山市| 马关县| 江华| 兰坪| 罗源县| 新绛县|